using StructureMap; using StructureMap.Pipeline; using Stylet; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Bootstrappers { public class StructureMapBootstrapper : BootstrapperBase where TRootViewModel : class { private IContainer container; protected override void ConfigureBootstrapper() { this.Configure(); this.container = new Container(config => { this.DefaultConfigureIoC(config); this.ConfigureIoC(config); }); } /// /// 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(ConfigurationExpression config) { config.For().Add(this); config.For().Add().LifecycleIs(); config.For().Add().LifecycleIs(); config.For().Add().LifecycleIs(); config.For().Add().LifecycleIs(); foreach (var assembly in this.Assemblies) { config.Scan(x => x.Assembly(assembly)); } } /// /// Override to add your own types to the IoC container. /// protected virtual void ConfigureIoC(ConfigurationExpression config) { } public override object GetInstance(Type type) { return this.container.GetInstance(type); } } }