public void RegistersDbContext_PropertyInjecting_GreenfieldDbInitializer_Transiently_WhenSettingIsGreenfield() { var container = new Container(); container.ComposeRoot(new RootCompositionSettings { IsGreenfield = true, }); using (container.BeginLifetimeScope()) { var dbContext = container.GetInstance<EntityDbContext>(); dbContext.Initializer.ShouldNotBeNull(); dbContext.Initializer.ShouldBeType<GreenfieldDbInitializer>(); } }
public void RegistersIDbInitializer_UsingGreenfieldDbInitializer_Transiently_WhenSettingIsGreenfield() { var container = new Container(); container.ComposeRoot(new RootCompositionSettings { IsGreenfield = true, }); var instance = container.GetInstance<IDatabaseInitializer<EntityDbContext>>(); var registration = container.GetRegistration(typeof(IDatabaseInitializer<EntityDbContext>)); instance.ShouldNotBeNull(); instance.ShouldBeType<GreenfieldDbInitializer>(); registration.Lifestyle.ShouldEqual(Lifestyle.Transient); }
public void RegistersICustomizeDb_UsingSqlServerDbCustomizer_Transiently_WhenSettingIsGreenfield() { var container = new Container(); container.ComposeRoot(new RootCompositionSettings { IsGreenfield = true, }); var instance = container.GetInstance<ICustomizeDb>(); var registration = container.GetRegistration(typeof(ICustomizeDb)); instance.ShouldNotBeNull(); instance.ShouldBeType<SqlServerScriptsCustomizer>(); registration.Lifestyle.ShouldEqual(Lifestyle.Transient); }
public CompositionRootFixture() { HttpContext.Current = null; Container = new Container(); var assemblies = new[] { Assembly.GetExecutingAssembly() }; var settings = new RootCompositionSettings { FluentValidatorAssemblies = assemblies, QueryHandlerAssemblies = assemblies, CommandHandlerAssemblies = assemblies, }; Container.ComposeRoot(settings); }
public static void Configure() { var container = new Container(); var settings = new RootCompositionSettings { #if DEBUG IsGreenfield = true, #endif FluentValidatorAssemblies = new[] { Assembly.GetAssembly(typeof(IHandleCommand<>)), Assembly.GetExecutingAssembly(), }, }; container.ComposeRoot(settings); container.RegisterMvcControllers(Assembly.GetExecutingAssembly()); container.RegisterMvcAttributeFilterProvider(); container.Verify(); DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); GlobalConfiguration.Configuration.DependencyResolver = new WebApiDependencyResolver(container); FluentValidation.Mvc.FluentValidationModelValidatorProvider.Configure( provider => { provider.ValidatorFactory = new ValidatorFactory(container); provider.AddImplicitRequiredValidator = false; } ); FluentValidation.Mvc.WebApi.FluentValidationModelValidatorProvider.Configure(provider => { provider.ValidatorFactory = new ValidatorFactory(container); }); }
public void ComposeRoot_UsesDefaultSettings_WhenNoneArePassed() { var container = new Container(); container.ComposeRoot(null); }
/// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary> public static void RegisterDependencies() { // compose the root var container = new Container( new ContainerOptions { AllowOverridingRegistrations = true, }); var rootCompositionSettings = new RootCompositionSettings { Flags = RootCompositionFlags.Web | RootCompositionFlags.Work, FluentValidationAssemblies = new[] { Assembly.GetAssembly(typeof(IHandleCommands<>)), Assembly.GetExecutingAssembly(), } }; container.ComposeRoot(rootCompositionSettings); container.RegisterMvcControllers(Assembly.GetExecutingAssembly()); container.RegisterMvcAttributeFilterProvider(); container.RegisterHttpFilterProvider(); container.Verify(); DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorHttpDependencyResolver(container); FluentValidationModelValidatorProvider.Configure( provider => { provider.ValidatorFactory = new FluentValidationValidatorFactory(container); provider.AddImplicitRequiredValidator = false; } ); // seed data if (rootCompositionSettings.Flags.HasFlag(RootCompositionFlags.Debug)) { var seeder = container.GetInstance<ISeedData>(); if (seeder != null) seeder.Seed(); } // fire up poor man's worker role if (rootCompositionSettings.Flags.HasFlag(RootCompositionFlags.Work) && rootCompositionSettings.Flags.HasFlag(RootCompositionFlags.Debug) && !rootCompositionSettings.Flags.HasFlag(RootCompositionFlags.Azure)) { var cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = cancellationTokenSource.Token; Task.Factory.StartNew(() => { var workerRole = DependencyResolver.Current.GetService<WebDevelopmentWorkerRole>(); workerRole.OnStart(); workerRole.Run(cancellationToken); }, cancellationToken); AppDomain.CurrentDomain.DomainUnload += (sender, args) => cancellationTokenSource.Cancel(); } }