/// <summary> /// Initializes the default DI <see cref="Services"/> container and runs initialization methods. A shortcut around the <see cref="SetupContainer(ContainerBuilder, IAppPlatform, Assembly[])"/> and <see cref="RunInitMethods"/>. /// </summary> /// <param name="platform">The app platform that this <see cref="App"/> will use for native services.</param> /// <param name="assemblies">The assemblies for this platform that contain any <see cref="IView"/>s or <see cref="IPlatformModule"/>s that the <see cref="App"/> requires.</param> public void Initialize(IAppPlatform platform, params Assembly[] assemblies) { var builder = new ContainerBuilder(); SetupContainer(builder, platform, assemblies); Services = builder.Build(); RunInitMethods(); }
/// <summary> /// Sets up an Autofac <see cref="ContainerBuilder"/> with all of the <see cref="App"/> dependencies. Called internally by <see cref="Initialize(IAppPlatform, Assembly[])"/>. /// </summary> /// <param name="builder">The Autofac <see cref="ContainerBuilder"/> to register services to.</param> /// <param name="platform">The app platform that this <see cref="App"/> will use for native services.</param> /// <param name="assemblies">The assemblies for this platform that contain any <see cref="IView"/>s or <see cref="IPlatformModule"/>s that the <see cref="App"/> requires.</param> public void SetupContainer(ContainerBuilder builder, IAppPlatform platform, params Assembly[] assemblies) { Assembly[] fullAssemblies = assemblies .Concat(new Assembly[] { typeof(App).Assembly }) .ToArray(); platform.ConfigureServices(builder); //// Register any internal services that deal with lifecycle of the app. builder.RegisterAssemblyTypes(fullAssemblies) .AssignableTo <ILifecycleHandler>() .AsImplementedInterfaces(); //// Register any IPlatformModules as both modules and types. builder.RegisterAssemblyModules <IPlatformModule>(fullAssemblies); builder.RegisterAssemblyTypes(fullAssemblies) .AssignableTo <IPlatformModule>() .AsImplementedInterfaces() .SingleInstance(); //// Register default navigation components. builder.RegisterAssemblyTypes(typeof(App).Assembly) .AssignableTo <INavigationHistory>() .AsImplementedInterfaces() .SingleInstance(); builder.RegisterAssemblyTypes(typeof(App).Assembly) .AssignableTo <INavigationLayer>() .AsImplementedInterfaces(); builder.RegisterAssemblyTypes(typeof(App).Assembly) .AssignableTo <INavigationService>() .AsImplementedInterfaces() .SingleInstance(); //// Register default commanding components. builder.RegisterAssemblyTypes(typeof(App).Assembly) .AssignableTo <ICommandRouter>() .AsImplementedInterfaces() .SingleInstance(); //// If all a service needs is app information (such as name), the IPackageInfo is registered separately. builder.RegisterInstance <IPackageInfo>(this.PackageInfo); //// Registers required views. builder.RegisterViews(assemblies); //// Calls App-specific configuration. this.ConfigureServices(builder); }
public void CreateApps() { DefaultApp = new TestingApp(); AppPlatform = new TestingAppPlatform(builder => { builder.Register <IViewProvider>(c => Mock.Of <IViewProvider>()) .SingleInstance() .AsImplementedInterfaces(); builder.Register <IBackgroundService>(c => Mock.Of <IBackgroundService>()) .SingleInstance() .AsImplementedInterfaces(); builder.Register <IStorageService>(c => Mock.Of <IStorageService>()) .AsImplementedInterfaces(); builder.Register <ISettingsService>(c => Mock.Of <ISettingsService>()) .AsImplementedInterfaces(); builder.Register <IDispatcher>(c => Mock.Of <IDispatcher>()) .AsImplementedInterfaces(); builder.Register <INotificationService>(c => Mock.Of <INotificationService>()) .AsImplementedInterfaces(); builder.Register <ILauncher>(c => Mock.Of <ILauncher>()) .AsImplementedInterfaces(); }); }
public static void SetPlatform(IAppPlatform p) { Platform = p; }