/// <summary> /// Registers the Caliburn.Micro services with the container. /// </summary> /// <param name="treatViewAsLoaded">if set to <c>true</c> [treat view as loaded].</param> public void RegisterPhoneServices(bool treatViewAsLoaded = false) { var toSearch = AssemblySource.Instance.ToArray().Union(new[] { typeof(IStorageMechanism).Assembly }); foreach (var assembly in toSearch) { this.AllTypesOf<IStorageMechanism>(assembly); this.AllTypesOf<IStorageHandler>(assembly); } var phoneService = new PhoneApplicationServiceAdapter(rootFrame); var navigationService = new FrameAdapter(rootFrame, treatViewAsLoaded); RegisterInstance(typeof(SimpleContainer), null, this); RegisterInstance(typeof(PhoneContainer), null, this); RegisterInstance(typeof(IPhoneContainer), null, this); RegisterInstance(typeof(INavigationService), null, navigationService); RegisterInstance(typeof(IPhoneService), null, phoneService); RegisterSingleton(typeof(IEventAggregator), null, typeof(EventAggregator)); RegisterSingleton(typeof(IWindowManager), null, typeof(WindowManager)); RegisterSingleton(typeof(StorageCoordinator), null, typeof(StorageCoordinator)); var coordinator = (StorageCoordinator)GetInstance(typeof(StorageCoordinator), null); coordinator.Start(); RegisterSingleton(typeof(TaskController), null, typeof(TaskController)); var taskController = (TaskController)GetInstance(typeof(TaskController), null); taskController.Start(); }
/// <summary> /// Registers the Caliburn.Micro services with the container. /// </summary> /// <param name="treatViewAsLoaded">if set to <c>true</c> [treat view as loaded].</param> public void RegisterPhoneServices(bool treatViewAsLoaded = false) { var toSearch = AssemblySource.Instance.ToArray().Union(new[] { typeof(IStorageMechanism).Assembly }); foreach (var assembly in toSearch) { this.AllTypesOf <IStorageMechanism>(assembly); this.AllTypesOf <IStorageHandler>(assembly); } var phoneService = new PhoneApplicationServiceAdapter(rootFrame); var navigationService = new FrameAdapter(rootFrame, treatViewAsLoaded); RegisterInstance(typeof(SimpleContainer), null, this); RegisterInstance(typeof(PhoneContainer), null, this); RegisterInstance(typeof(IPhoneContainer), null, this); RegisterInstance(typeof(INavigationService), null, navigationService); RegisterInstance(typeof(IPhoneService), null, phoneService); RegisterSingleton(typeof(IEventAggregator), null, typeof(EventAggregator)); RegisterSingleton(typeof(IWindowManager), null, typeof(WindowManager)); RegisterSingleton(typeof(IVibrateController), null, typeof(SystemVibrateController)); RegisterSingleton(typeof(ISoundEffectPlayer), null, typeof(XnaSoundEffectPlayer)); RegisterSingleton(typeof(StorageCoordinator), null, typeof(StorageCoordinator)); var coordinator = (StorageCoordinator)GetInstance(typeof(StorageCoordinator), null); coordinator.Start(); RegisterSingleton(typeof(TaskController), null, typeof(TaskController)); var taskController = (TaskController)GetInstance(typeof(TaskController), null); taskController.Start(); }
/// <summary> /// Registers the Caliburn.Micro navigation service with the container. /// </summary> /// <param name="rootFrame">The application root frame.</param> /// <param name="treatViewAsLoaded">if set to <c>true</c> [treat view as loaded].</param> public INavigationService RegisterNavigationService(Frame rootFrame, bool treatViewAsLoaded = false) { if (HasHandler(typeof (INavigationService), null)) return this.GetInstance<INavigationService>(null); if (rootFrame == null) throw new ArgumentNullException("rootFrame"); var frameAdapter = new FrameAdapter(rootFrame, treatViewAsLoaded); RegisterInstance(typeof (INavigationService), null, frameAdapter); return frameAdapter; }
/// <summary> /// Registers the Caliburn.Micro navigation service with the container. /// </summary> /// <param name="rootFrame">The application root frame.</param> /// <param name="treatViewAsLoaded">if set to <c>true</c> [treat view as loaded].</param> /// <param name="cacheViewModels">if set to <c>true</c> then navigation service cache view models for resuse.</param> public INavigationService RegisterNavigationService(Frame rootFrame, bool treatViewAsLoaded = false, bool cacheViewModels = false) { if (HasHandler(typeof (INavigationService), null)) return this.GetInstance<INavigationService>(null); if (rootFrame == null) throw new ArgumentNullException("rootFrame"); #if WinRT81 var frameAdapter = cacheViewModels ? (INavigationService) new CachingFrameAdapter(rootFrame, treatViewAsLoaded) : new FrameAdapter(rootFrame, treatViewAsLoaded); #else var frameAdapter = new FrameAdapter(rootFrame, treatViewAsLoaded); #endif RegisterInstance(typeof (INavigationService), null, frameAdapter); return frameAdapter; }
/// <summary> /// Registers the Caliburn.Micro navigation service with the container. /// </summary> /// <param name="rootFrame">The application root frame.</param> /// <param name="treatViewAsLoaded">if set to <c>true</c> [treat view as loaded].</param> public INavigationService RegisterNavigationService(Frame rootFrame, bool treatViewAsLoaded = false) { if (HasHandler(typeof(INavigationService), null)) { return(this.GetInstance <INavigationService>(null)); } if (rootFrame == null) { throw new ArgumentNullException("rootFrame"); } var frameAdapter = new FrameAdapter(rootFrame, treatViewAsLoaded); RegisterInstance(typeof(INavigationService), null, frameAdapter); return(frameAdapter); }
/// <summary> /// Registers the Caliburn.Micro navigation service with the container. /// </summary> /// <param name="rootFrame">The application root frame.</param> /// <param name="treatViewAsLoaded">if set to <c>true</c> [treat view as loaded].</param> /// <param name="cacheViewModels">if set to <c>true</c> then navigation service cache view models for resuse.</param> public INavigationService RegisterNavigationService(Frame rootFrame, bool treatViewAsLoaded = false, bool cacheViewModels = false) { if (HasHandler(typeof(INavigationService), null)) { return(this.GetInstance <INavigationService>(null)); } if (rootFrame == null) { throw new ArgumentNullException("rootFrame"); } #if WinRT81 var frameAdapter = cacheViewModels ? (INavigationService) new CachingFrameAdapter(rootFrame, treatViewAsLoaded) : new FrameAdapter(rootFrame, treatViewAsLoaded); #else var frameAdapter = new FrameAdapter(rootFrame, treatViewAsLoaded); #endif RegisterInstance(typeof(INavigationService), null, frameAdapter); return(frameAdapter); }
protected override void Configure() { // configure container var builder = new ContainerBuilder(); // register phone services var caliburnAssembly = typeof(IStorageMechanism).Assembly; // register IStorageMechanism implementors builder.RegisterAssemblyTypes(caliburnAssembly) .Where( type => typeof(IStorageMechanism).IsAssignableFrom(type) && !type.IsAbstract && !type.IsInterface) .As<IStorageMechanism>() .InstancePerLifetimeScope(); // register IStorageHandler implementors builder.RegisterAssemblyTypes(caliburnAssembly) .Where( type => typeof(IStorageHandler).IsAssignableFrom(type) && !type.IsAbstract && !type.IsInterface) .As<IStorageHandler>() .InstancePerLifetimeScope(); // register services builder.RegisterAssemblyTypes(AssemblySource.Instance.ToArray()) .Where(type => type.Name.EndsWith("Service") && type.IsClass && !type.IsAbstract) .AsImplementedInterfaces() .InstancePerLifetimeScope(); // register view models builder.RegisterAssemblyTypes(AssemblySource.Instance.ToArray()) .Where(type => type.Name.EndsWith("ViewModel")) .AsSelf() .InstancePerLifetimeScope(); // register views builder.RegisterAssemblyTypes(AssemblySource.Instance.ToArray()) .Where(type => type.Name.EndsWith("View")) .AsSelf() .InstancePerLifetimeScope(); builder.RegisterInstance<IPhoneContainer>(new AutofacPhoneContainer()).SingleInstance(); // register the singletons var frameAdapter = new FrameAdapter(this.RootFrame); var phoneServices = new PhoneApplicationServiceAdapter(this.RootFrame); builder.RegisterInstance(frameAdapter).As<INavigationService>(); builder.RegisterInstance(phoneServices).As<IPhoneService>(); builder.RegisterType<EventAggregator>().As<IEventAggregator>().SingleInstance(); builder.RegisterType<WindowManager>().As<IWindowManager>().SingleInstance(); builder.RegisterType<StorageCoordinator>().AsSelf().SingleInstance(); builder.RegisterType<TaskController>().AsSelf().SingleInstance(); // build the container this.container = builder.Build(); // start services this.container.Resolve<StorageCoordinator>().Start(); this.container.Resolve<TaskController>().Start(); // Initialize IoC-Container utility IoC.Initialize(this.container); AddCustomConventions(); }
public void RegisterNavigationService(Frame rootFrame, bool treatViewAsLoaded = false) { var navService = new FrameAdapter(rootFrame, treatViewAsLoaded); Kernel.Rebind<INavigationService>().ToMethod<FrameAdapter>(x => navService); }