An implementation of IPhoneService that adapts PhoneApplicationService.
Inheritance: IPhoneService
Example #1
0
        /// <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 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();
        }
Example #3
0
        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();
        }