当前位置: 首页>>代码示例>>C#>>正文


C# Container.Configure方法代码示例

本文整理汇总了C#中Container.Configure方法的典型用法代码示例。如果您正苦于以下问题:C# Container.Configure方法的具体用法?C# Container.Configure怎么用?C# Container.Configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Container的用法示例。


在下文中一共展示了Container.Configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BootStrapContainer

        private static IContainer BootStrapContainer()
        {
            var container =
                new Container(x => x.For<ProcessCoordinatorService>()
                                    .LifecycleIs(new SingletonLifecycle())
                                    .Use<ProcessCoordinatorService>());

            container.Configure(cfg => cfg.For<IServiceBus>()
                                           .LifecycleIs(new SingletonLifecycle())
                                           .Use(context => ServiceBusFactory.New(sbc => {
                                               sbc.ReceiveFrom(
                                                   "rabbitmq://localhost/DirectOnTime_ProcessCoordinator");
                                               sbc.UseRabbitMq();
                                               sbc.UseRabbitMqRouting();
                                               sbc.UseControlBus();
                                               sbc.Subscribe(
                                                   subs =>
                                                   subs.LoadFrom(container));
                                           }
                                                               )));
            container.Configure(cfg => cfg.For(typeof(ISagaRepository<>))
                .LifecycleIs(new SingletonLifecycle())
                .Use(typeof(InMemorySagaRepository<>))
                );

            return container;
        }
开发者ID:bolineni,项目名称:DirectOnTime,代码行数:27,代码来源:Program.cs

示例2: Compose

    public static IDependencyInjectionContainer Compose()
    {
        // Create the DI container
        var container = new Container();

          container.Configure(expression =>
          {
        expression.For<DomainService<Course>>().HybridHttpOrThreadLocalScoped().Use<CourseDomainSource>();
        expression.For<DomainService<Lead>>().HybridHttpOrThreadLocalScoped().Use<LeadDomainService>();
        expression.For<DomainService<User>>().HybridHttpOrThreadLocalScoped().Use<UserDomainService>();
        expression.For<DomainService<Country>>().HybridHttpOrThreadLocalScoped().Use<CountryDomainService>();

        expression.For<DataProvider<Course>>().HybridHttpOrThreadLocalScoped().Use<CourseDataProvider>();
        expression.For<DataProvider<Lead>>().HybridHttpOrThreadLocalScoped().Use<LeadDataProvider>();
        expression.For<DataProvider<User>>().HybridHttpOrThreadLocalScoped().Use<UserDataProvider>();
        expression.For<DataProvider<Country>>().HybridHttpOrThreadLocalScoped().Use<CountryDataProvider>();
        expression.Scan(scanner =>
        {
          scanner.TheCallingAssembly();
          scanner.WithDefaultConventions();
        });
          });

        // Setup configuration of DI
        container.Configure(r => r.AddRegistry<MvcSiteMapProviderRegistry>());

        #if DEBUG
        container.AssertConfigurationIsValid();
        #endif

        // Return our DI container wrapper instance
        return new StructureMapDependencyInjectionContainer(container);
    }
开发者ID:shanmukhig,项目名称:tms_optimized,代码行数:33,代码来源:CompositionRoot.cs

示例3: Application_Start

        protected void Application_Start()
        {
            var container = new Container();
            HttpContext.Current.Application.Add("Container", container); // Add the container to the context so the ObjectFactory can use it later.

            container.Configure(cfg =>
            {
                cfg.AddRegistry<ServiceRegistry>();
                cfg.AddRegistry<LoggerRegistry>();
                cfg.AddRegistry<MessagingRegistry>();
            });

            _busControl = MassTransitConfig.ConfigureBus(container);

            container.Configure(cfg =>
            {
                cfg.For<IBusControl>().Use(_busControl);
                cfg.Forward<IBus, IBusControl>(); // Doesn't seem to work
            });

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            LoggingConfig.ConfigureLog4Net();

            _busControl.Start();
        }
开发者ID:LouisKruger,项目名称:MassTransitExample,代码行数:29,代码来源:Global.asax.cs

示例4: Main

        static void Main(string[] args)
        {
            Container container = new Container(); // requires full .NET 4 targetted framework
            container.Configure(reg => reg.For<IBillingProcessor>().Use<BillingProcessor>());
            container.Configure(reg => reg.For<ICustomer>().Use<Customer>());
            container.Configure(reg => reg.For<INotifier>().Use<Notifier>());
            container.Configure(reg => reg.For<ILogger>().Use<Logger>());

            Console.WriteLine("StructureMap DI Container Example");
            Console.WriteLine();

            OrderInfo orderInfo = new OrderInfo()
            {
                CustomerName = "Miguel Castro",
                Email = "[email protected]",
                Product = "Laptop",
                Price = 1200,
                CreditCard = "1234567890"
            };

            Console.WriteLine("Production:");
            Console.WriteLine();

            Commerce commerce = container.GetInstance<Commerce>();
            commerce.ProcessOrder(orderInfo);

            Console.WriteLine();
            Console.WriteLine("Press [Enter] to exit...");
            Console.ReadLine();
        }
开发者ID:tleviathan,项目名称:DeepDiveIntoDI,代码行数:30,代码来源:Program.cs

示例5: should_return_true_and_instance_should_not_be_null_if_provided_type_can_be_resolved

        public void should_return_true_and_instance_should_not_be_null_if_provided_type_can_be_resolved()
        {
            var container = new Container();

            object o;
            container.TryGet(typeof(object), out o).ShouldBe(true);
            o.ShouldNotBe(null);

            container.TryGet(out o).ShouldBe(true);
            o.ShouldNotBe(null);

            container.Configure(x => x.For<IDisposable>().Use<Disposable>());

            container.TryGet(typeof(IDisposable), out o).ShouldBe(true);
            o.ShouldNotBe(null);

            IDisposable disposable;
            container.TryGet(out disposable).ShouldBe(true);
            disposable.ShouldNotBe(null);

            var namedDisposable = new Disposable();
            container.Configure(x => x.For<IDisposable>("xyz").Use(namedDisposable));

            TestClassWithDisposable testClassWithDisposable;
            container.TryGet(out testClassWithDisposable).ShouldBe(true);
            testClassWithDisposable.ShouldNotBe(null);
            testClassWithDisposable.Disposable.ShouldNotBe(namedDisposable);

            container.TryGet("xyz", out testClassWithDisposable).ShouldBe(true);
            testClassWithDisposable.ShouldNotBe(null);
            testClassWithDisposable.Disposable.ShouldBe(namedDisposable);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:32,代码来源:try_get_instance.cs

示例6: do_not_allow

 public void do_not_allow()
 {
     var container = new Container();
     Exception<StructureMapConfigurationException>.ShouldBeThrownBy(
         () =>
         {
             container.Configure(x => container.Configure(y => { }));
         });
 }
开发者ID:khellang,项目名称:structuremap,代码行数:9,代码来源:do_not_allow_recursive_container_configure.cs

示例7: Resolve

 public static void Resolve()
 {
     var container = new Container();
     StatWinner.Common.DependencyInjection.DependencyContainer = container;
     container.Configure(
         x =>
             x.For<IConfigurationManager>()
                 .LifecycleIs(new SingletonLifecycle())
                 .Use<MongoDBConfigurationManager>());
     container.Configure(x => x.For<IUserAccountManagement>().Use<MongoUserAccountManagement>());
     container.Configure(x => x.For<IEventManagement>().Use<MongoEventManagement>());
 }
开发者ID:GTigran,项目名称:StatWinner,代码行数:12,代码来源:DependencyResolver.cs

示例8: should_not_resolve_value_type_arrays_unless_the_array_type_is_registered

        public void should_not_resolve_value_type_arrays_unless_the_array_type_is_registered()
        {
            var array = new[] { 1, 2, 3 };
            var container = new Container();

            container.Get<TypeWithArrayOfValueTypeDependency>().Ints.Should().BeNull();

            container.Configure(x => x.For<int>().Add(0));
            container.Get<TypeWithArrayOfValueTypeDependency>().Ints.Should().BeNull();

            container.Configure(x => x.For<int[]>().Use(array));
            container.Get<TypeWithArrayOfValueTypeDependency>().Ints.Should().BeEquivalentTo(array);
        }
开发者ID:JonasSamuelsson,项目名称:Maestro,代码行数:13,代码来源:resolve_array_dependencies.cs

示例9: Main

		public static void Main(string[] args)
		{
			var container = new Container();
			container.Configure(x => x.For<ICreditCard>().Use<MasterCard>().Named("master"));
			container.Configure(x => x.For<ICreditCard>().Use<VisaCard>().Named("visa"));

			var creditCard = container.GetInstance<ICreditCard>("master");

			//var shopper = container.GetInstance<Shopper>();
			var shopper = new Shopper(creditCard);
			shopper.Charge();

			Console.Read();
		}
开发者ID:dance2die,项目名称:Demo.Ioc,代码行数:14,代码来源:Program.cs

示例10: ConfigureDependencies

        private static IContainer ConfigureDependencies()
        {
            var container = new Container(x =>x.AddRegistry(new PersistenceRegistery()));

            container.Configure(x => x.For<IBusinessManagerContainer>().Use<BusinessManagerContainer>());

            container.Configure(x => x.For<IBusinessManagerInvocationLogger>().Singleton().Use<SqlProcBusinessManagerInvocationLogger>());
            container.Configure(x => x.For<IBusinessManagerRegistery>().Use<BusinessManagerRegistery>());
            
            
            container.Configure(x => x.For<IConnectionString>().Use(new ConnectionString("KafalaDB")));
            container.Configure(x => x.For<IFlashMessenger>().Use<SwallowFlashMessneger>());
            return container;
        }
开发者ID:AbdoNile,项目名称:Foundation.Old,代码行数:14,代码来源:Program.cs

示例11: Main

        public static void Main(string[] args)
        {
            var app = new App { ShutdownMode = ShutdownMode.OnLastWindowClose };
            app.InitializeComponent();

           var container =  new Container(x=> x.AddRegistry<AppRegistry>());


           var factory = container.GetInstance<TraderWindowFactory>();
           var window = factory.Create(true);
           container.Configure(x => x.For<Dispatcher>().Add(window.Dispatcher));

            //run start up jobs
            var priceUpdater = container.GetInstance<TradePriceUpdateJob>();


            window.Show();

            app.Resources.Add(SystemParameters.ClientAreaAnimationKey, null);
            app.Resources.Add(SystemParameters.MinimizeAnimationKey, null);
            app.Resources.Add(SystemParameters.UIEffectsKey, null);


            app.Run();
        }
开发者ID:sk8tz,项目名称:TradingDemo,代码行数:25,代码来源:BootStrap.cs

示例12: SetUp

        public void SetUp()
        {
            AssetDeclarationVerificationActivator.Latched = true;

            registry = new FubuRegistry(x =>
            {

                x.Route("area/sub/{Name}/{Age}")
                    .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();

                x.Route("area/sub2/prop")
                    .Calls<TestController>(c => c.SomeAction(null)).OutputToJson();

                x.Route("area/sub2/{Name}/{Age}")
                    .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();

                x.Route("area/sub2/{Name}")
                    .Calls<TestController>(c => c.ThirdAction(null)).OutputToJson();

                x.Route("area/sub3/{Name}/{Age}")
                    .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();

                x.Route("area/sub4/some_pattern")
                    .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();
            });

            container = new Container();

            routes = FubuApplication.For(registry).StructureMap(container).Bootstrap().Where(r => !r.As<Route>().Url.StartsWith("_content")).ToList();

            container.Configure(x => x.For<IOutputWriter>().Use(new InMemoryOutputWriter()));
            Debug.WriteLine(container.WhatDoIHave());
        }
开发者ID:hartez,项目名称:fubumvc,代码行数:33,代码来源:FubuBootstrapperIntegrationTester.cs

示例13: Scanning_Assemblies_For_Components

        public void Scanning_Assemblies_For_Components()
        {
            // most alternative containers to Unity support this out of the box
            // you can get 3rd party libraries to extend Unity (or DIY)

            var structureMap = new Container();
            structureMap.Configure(_ => _.Scan(a =>
            {
                a.TheCallingAssembly();
                a.WithDefaultConventions();
            }));
            Assert.IsNotNull(structureMap.GetInstance<IFirst1>());

            var windsor = new WindsorContainer();
            windsor.Register(Classes.FromThisAssembly()
                .Pick()
                //.Where(t=>t)
                .WithServiceDefaultInterfaces());
            Assert.IsNotNull(windsor.Resolve<IFirst1>());

            var ninject = new StandardKernel();
            ninject.Bind(x => x.FromThisAssembly()
                .SelectAllClasses()
                .BindDefaultInterfaces());
            Assert.IsNotNull(ninject.Get<IFirst1>());

            var autofacBuilder = new ContainerBuilder();
            autofacBuilder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                .AsImplementedInterfaces();
            var autofac = autofacBuilder.Build();
            Assert.IsNotNull(autofac.Resolve<IFirst1>());

            // "scan everything" isn't exactly a convention, so let's take a look at some examples
        }
开发者ID:bling,项目名称:AdvancedIocTechniques,代码行数:34,代码来源:06.cs

示例14: Main

        static void Main(string[] args)
        {
            var container = new Container(cfg =>
                                          	{
                                          		cfg.AddRegistry<CalculatorRegistry>();
                                                cfg.AddRegistry<RepositoryRegistry>();

                                                cfg.For<ILogger>().Use<Logger>();
                                            });

            var productRepository = container.GetInstance<IProductRepository>();
            var product = productRepository.Find(1);

            var taxCalculator = container.GetInstance<ITaxCalculator>();
            Console.WriteLine("Tax is: {0:C}", taxCalculator.CalculateTax(product));

            container.Configure(cfg =>
                                    {
                                        cfg.For<ILogger>().Use<NullLogger>();
                                    });

            var shippingCalculator = container.GetInstance<IShippingCalculator>();
            Console.WriteLine("Shipping is: {0:C}", shippingCalculator.CalculateRate(product));

            Console.WriteLine("Are they equal? " + container.GetInstance<IShippingCalculator>().Equals(container.GetInstance<IShippingCalculator>()));
        }
开发者ID:MattHoneycutt,项目名称:Presentations,代码行数:26,代码来源:Program.cs

示例15: configure_the_container_using_auto_registrations_and_conventions

        public void configure_the_container_using_auto_registrations_and_conventions()
        {
            // SAMPLE: quickstart-configure-the-container-using-auto-registrations-and-conventions
            // Example #1
            var container1 = new Container(c =>
            c.Scan(scanner =>
            {
            scanner.TheCallingAssembly();
            scanner.WithDefaultConventions();
            }));

            // Example #2
            var container2 = new Container();

            container2.Configure(c =>
            c.Scan(scanner =>
            {
            scanner.TheCallingAssembly();
            scanner.WithDefaultConventions();
            }));

            // Example #3
            ObjectFactory.Initialize(i =>
            i.Scan(scanner =>
            {
            scanner.TheCallingAssembly();
            scanner.WithDefaultConventions();
            }));
            // ENDSAMPLE
        }
开发者ID:e-tobi,项目名称:structuremap,代码行数:30,代码来源:configuring_the_container.cs


注:本文中的Container.Configure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。