using Autofac; using Stylet; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Bootstrappers { public class AutofacBootstrapper : BootstrapperBase where TRootViewModel : class { private IContainer container; protected override void ConfigureBootstrapper() { this.Configure(); var builder = new ContainerBuilder(); this.DefaultConfigureIoC(builder); this.ConfigureIoC(builder); this.container = builder.Build(); } /// /// Override to configure your IoC container, and anything else /// protected virtual void Configure() { } /// /// Carries out default configuration of the IoC container. Override if you don't want to do this /// protected virtual void DefaultConfigureIoC(ContainerBuilder builder) { builder.RegisterInstance(this); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As(); // Not singleton! builder.RegisterAssemblyTypes(this.Assemblies.ToArray()); } /// /// Override to add your own types to the IoC container. /// protected virtual void ConfigureIoC(ContainerBuilder builder) { } protected override object GetInstance(Type type) { return this.container.Resolve(type); } } }