當前位置: 首頁>>代碼示例>>C#>>正文


C# Container.ComposeRoot方法代碼示例

本文整理匯總了C#中SimpleInjector.Container.ComposeRoot方法的典型用法代碼示例。如果您正苦於以下問題:C# Container.ComposeRoot方法的具體用法?C# Container.ComposeRoot怎麽用?C# Container.ComposeRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SimpleInjector.Container的用法示例。


在下文中一共展示了Container.ComposeRoot方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: RegistersDbContext_PropertyInjecting_GreenfieldDbInitializer_Transiently_WhenSettingIsGreenfield

 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>();
     }
 }
開發者ID:phobos04,項目名稱:tripod,代碼行數:11,代碼來源:CompositionRootTests.cs

示例2: RegistersIDbInitializer_UsingGreenfieldDbInitializer_Transiently_WhenSettingIsGreenfield

        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);
        }
開發者ID:phobos04,項目名稱:tripod,代碼行數:11,代碼來源:CompositionRootTests.cs

示例3: RegistersICustomizeDb_UsingSqlServerDbCustomizer_Transiently_WhenSettingIsGreenfield

        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);
        }
開發者ID:phobos04,項目名稱:tripod,代碼行數:11,代碼來源:CompositionRootTests.cs

示例4: CompositionRootFixture

 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);
 }
開發者ID:phobos04,項目名稱:tripod,代碼行數:13,代碼來源:CompositionRootFixture.cs

示例5: Configure

        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);
            });
        }
開發者ID:phobos04,項目名稱:tripod,代碼行數:36,代碼來源:ServicesConfig.cs

示例6: ComposeRoot_UsesDefaultSettings_WhenNoneArePassed

 public void ComposeRoot_UsesDefaultSettings_WhenNoneArePassed()
 {
     var container = new Container();
     container.ComposeRoot(null);
 }
開發者ID:phobos04,項目名稱:tripod,代碼行數:5,代碼來源:CompositionRootTests.cs

示例7: RegisterDependencies

        /// <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();
            }
        }
開發者ID:ucosmic,項目名稱:UCosmicAlpha,代碼行數:63,代碼來源:IocConfig.cs


注:本文中的SimpleInjector.Container.ComposeRoot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。