Adding dependency injection

This commit is contained in:
watsonb8
2020-01-31 20:41:45 -05:00
parent f8ad2f459e
commit 48d0ffa77d
27 changed files with 550 additions and 114 deletions

View File

@ -9,10 +9,11 @@ using Aurora.Proto.Party;
using Aurora.Proto.Events;
using Aurora.Services.ClientService;
using Aurora.Services.ClientService.Events;
using Aurora.Services.PlayerService;
using Aurora.Services.Player;
using Aurora.Services.EventManager;
using Aurora.Models.Media;
using Aurora.Design.Views.Party.NewPartyDialog;
using Aurora.Services.Settings;
namespace Aurora.Design.Views.Party
{
@ -32,22 +33,25 @@ namespace Aurora.Design.Views.Party
private ObservableCollection<PartyMember> _members;
private ObservableCollection<BaseMedia> _queue;
private BaseMedia _selectedMedia;
private ClientService _client;
private IClientService _client;
private ISettingsService _settingsService;
private int _selectedTabIndex;
public PartyViewModel()
public PartyViewModel(ISettingsService settingsService, IClientService clientService)
{
_members = new ObservableCollection<PartyMember>();
_queue = new ObservableCollection<BaseMedia>();
this._settingsService = settingsService;
SetState(PartyState.SelectingHost);
PlayCommand = new Command(OnDoubleClickCommandExecute, CanDoubleClickCommandExecute);
LeavePartyCommand = new Command(OnLeavePartyCommandExecute, CanLeavePartyCommandExecute);
_client = ClientService.Instance;
_client = clientService;
_client.OnMediaPaused += this.OnRemoteMediaPaused;
_client.OnMediaResumed += this.OnRemoteMediaResumed;
@ -245,7 +249,7 @@ namespace Aurora.Design.Views.Party
private async void OnJoinCommandExecute()
{
SetState(PartyState.Connecting);
_client.Start(_hostname, SettingsService.Instance.DefaultPort.ToString());
_client.Start(_hostname, this._settingsService.DefaultPort.ToString());
await JoinParty(false);
//TODO add cancellation token
@ -272,7 +276,7 @@ namespace Aurora.Design.Views.Party
ServerService.Instance.Start();
string localHost = ServerService.GetLocalIPAddress();
_client.IsHost = true;
_client.Start(localHost, SettingsService.Instance.DefaultPort.ToString());
_client.Start(localHost, this._settingsService.DefaultPort.ToString());
await JoinParty(true);
@ -387,10 +391,10 @@ namespace Aurora.Design.Views.Party
{
JoinPartyResponse resp = await _client.RemotePartyClient.JoinPartyAsync(new JoinPartyRequest
{
UserName = SettingsService.Instance.Username,
UserName = this._settingsService.Username,
});
SettingsService.Instance.ClientId = resp.ClientId;
this._settingsService.ClientId = resp.ClientId;
RefreshMembers();
@ -447,13 +451,13 @@ namespace Aurora.Design.Views.Party
req.EventTypes.Add(EventType.PartyMemberLeft);
req.EventTypes.Add(EventType.MediaPlaying);
req.EventTypes.Add(EventType.MediaStopped);
if (!string.IsNullOrWhiteSpace(SettingsService.Instance.ClientId))
if (!string.IsNullOrWhiteSpace(this._settingsService.ClientId))
{
req.ClientId = SettingsService.Instance.ClientId;
req.ClientId = this._settingsService.ClientId;
}
Console.WriteLine(string.Format("CLIENT {0} - SubscribeToEvents called from client with id", SettingsService.Instance.ClientId));
Console.WriteLine(string.Format("CLIENT {0} - SubscribeToEvents called from client with id", this._settingsService.ClientId));
await _client.RemoteEventClient.SubscribeToEventsAsync(req);
}
private async Task UnsubscribeFromEvents()