コード例 #1
0
 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>();
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 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);
 }
コード例 #5
0
ファイル: ServicesConfig.cs プロジェクト: phobos04/tripod
        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);
            });
        }
コード例 #6
0
 public void ComposeRoot_UsesDefaultSettings_WhenNoneArePassed()
 {
     var container = new Container();
     container.ComposeRoot(null);
 }
コード例 #7
0
ファイル: IocConfig.cs プロジェクト: ucosmic/UCosmicAlpha
        /// <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();
            }
        }