/// <remarks> /// AudioPlayer instances can share the same process. /// Static fields can be used to share state between AudioPlayer instances /// or to communicate with the Audio Streaming agent. /// </remarks> public AudioPlayer() { // since we are in a background agent : the types registered in the IoC container are not shared. IVersionDependentResourcesProvider versionDependentResourcesProvider = new VersionDependentResourcesProvider(); _audioTrackFactory = new AudioTrackFactory(versionDependentResourcesProvider); // TODO : Handle exceptions using (var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication()) { LoadAsciiUriFixes(userStoreForApplication); LoadPlayqueue(userStoreForApplication); } if (!_classInitialized) { _classInitialized = true; // Subscribe to the managed exception handler Deployment.Current.Dispatcher.BeginInvoke(delegate { Application.Current.UnhandledException += AudioPlayer_UnhandledException; }); } }
private void InitializeSettings() { EventAggregator eventAggregator = new EventAggregator(); IoC.Container.Bind <IEventAggregator>().ToConstant(eventAggregator); string synoSettings = "SynoSettings"; _openSynoSettings = IsolatedStorageSettings.ApplicationSettings.Contains(synoSettings) ? (OpenSynoSettings)IsolatedStorageSettings.ApplicationSettings[synoSettings] : new OpenSynoSettings(); // FIXME : Try to get rid of thses registrations and use DI instead. IoC.Container.Bind <IOpenSynoSettings>().ToConstant(_openSynoSettings); // FIXME : Load from config files instead of hard-coded bindings. IVersionDependentResourcesProvider versionDependentResourcesProvider = new VersionDependentResourcesProvider(); IoC.Container.Bind <IVersionDependentResourcesProvider>().ToConstant(versionDependentResourcesProvider).InSingletonScope(); // Retrieve the type IAudioStationSession from a config file, so we can change it. // Also possible : RemoteFileMockAudioStationSession IAudioStationSession audioStationSession; if (PhoneApplicationService.Current.State.ContainsKey("IAudioStationSession")) { audioStationSession = (IAudioStationSession)PhoneApplicationService.Current.State["IAudioStationSession"]; } else { audioStationSession = new AudioStationSession(versionDependentResourcesProvider, _openSynoSettings.DsmVersion) { Host = _openSynoSettings.Host, Port = _openSynoSettings.Port, Token = _openSynoSettings.Token }; } IoC.Container.Bind <IAudioStationSession>().ToConstant(audioStationSession).InSingletonScope(); // Retrieve the type SearchService from a config file, so we can change it. // also possible: MockSearchService; // IoC.Container.Bind<ISearchService>().To(typeof(MockSearchService)).InSingletonScope(); IoC.Container.Bind <ISearchService>().To(typeof(SearchService)).InSingletonScope(); IoC.Container.Bind <ISignInService>().To(typeof(SignInService)).InSingletonScope(); IoC.Container.Bind <IPageSwitchingService>().To <PageSwitchingService>().InSingletonScope(); IoC.Container.Bind <INavigatorService>().To <NavigatorService>().InSingletonScope(); IoC.Container.Bind <ISearchAllResultsViewModelFactory>().To <SearchAllResultsViewModelFactory>().InSingletonScope(); IoC.Container.Bind <SearchViewModel>().ToSelf().InSingletonScope(); IoC.Container.Bind <SearchResultsViewModelFactory>().ToSelf().InSingletonScope(); IoC.Container.Bind <ArtistPanoramaViewModelFactory>().ToSelf().InSingletonScope(); IoC.Container.Bind <ArtistDetailViewModelFactory>().To <ArtistDetailViewModelFactory>().InSingletonScope(); IoC.Container.Bind <ITrackViewModelFactory>().To <TrackViewModelFactory>(); IoC.Container.Bind <PlayQueueViewModel>().ToSelf().InSingletonScope(); IoC.Container.Bind <SearchResultsViewModel>().ToSelf().InSingletonScope(); _logService = new IsolatedStorageLogService(); IoC.Container.Bind <ILogService>().ToConstant(_logService).InSingletonScope(); IoC.Container.Bind <ISearchResultItemViewModelFactory>().To <SearchResultItemViewModelFactory>().InSingletonScope(); IoC.Container.Bind <IUrlParameterToObjectsPlateHeater>().To <UrlParameterToObjectsPlateHeater>().InSingletonScope(); IoC.Container.Bind <IAudioTrackFactory>().To <AudioTrackFactory>().InSingletonScope(); _notificationService = new NotificationService(); IoC.Container.Bind <INotificationService>().ToConstant(_notificationService).InSingletonScope(); ImageCachingService imageCachingService; if (IsolatedStorageSettings.ApplicationSettings.Contains("ImageCachingService")) { imageCachingService = (ImageCachingService)IsolatedStorageSettings.ApplicationSettings["ImageCachingService"]; imageCachingService.Initialize(); } else { // Todo : we should use a factory in order to have a mockable service. imageCachingService = new ImageCachingService(_logService); } imageCachingService.SaveRequested += this.ImageCachingServiceSaveRequested; IoC.Container.Bind <ImageCachingService>().ToConstant(imageCachingService).InSingletonScope(); IoC.Container.Bind <IPlaybackService>().To <PlaybackService>().InSingletonScope(); IoC.Container.Bind <AlbumViewModelFactory>().To <AlbumViewModelFactory>(); ActivateEagerTypes(); ResolvePrivateMembers(); }