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


C# Container.With方法代码示例

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


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

示例1: supply_defaults_by_generic_in_a_bunch

        public void supply_defaults_by_generic_in_a_bunch()
        {
            var container = new Container(x =>
            {
                x.For<IWidget>().Use<BWidget>();
                x.For<IService>().Use<AService>();
            });

            // SAMPLE: explicit-defaults-with-nested-closure
            var widget = new BWidget();
            var service = new BService();

            var guyWithWidgetAndService = container
                .With(x =>
                {
                    x.With<IWidget>(widget);
                    x.With<IService>(service);
                })
                .GetInstance<GuyWithWidgetAndService>();

            guyWithWidgetAndService
                .Widget.ShouldBeTheSameAs(widget);

            guyWithWidgetAndService
                .Service.ShouldBeTheSameAs(service);
            // ENDSAMPLE
        }
开发者ID:khellang,项目名称:structuremap,代码行数:27,代码来源:explicit_arguments.cs

示例2: supply_defaults_by_generic

        public void supply_defaults_by_generic()
        {
            // SAMPLE: explicit-arg-container
            var container = new Container(x =>
            {
                x.For<IWidget>().Use<BWidget>();
                x.For<IService>().Use<AService>();
            });
            // ENDSAMPLE

            // SAMPLE: explicit-fluent-interface
            var widget = new BWidget();
            var service = new BService();

            var guyWithWidgetAndService = container
                .With<IWidget>(widget)
                .With<IService>(service)
                .GetInstance<GuyWithWidgetAndService>();

            guyWithWidgetAndService
                .Widget.ShouldBeTheSameAs(widget);

            guyWithWidgetAndService
                .Service.ShouldBeTheSameAs(service);
            // ENDSAMPLE
        }
开发者ID:khellang,项目名称:structuremap,代码行数:26,代码来源:explicit_arguments.cs

示例3: ShouldResolveSingletonReplacement

        public void ShouldResolveSingletonReplacement()
        {
            var container = new Container();
            container.Register<InterfaceA, ClassA1>();

            var x = container.With<InterfaceA>(new ClassA2()).Resolve<ClassB>();

            Assert.IsInstanceOf<ClassA2>(x.A);
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:9,代码来源:With.cs

示例4: ShouldResolveHybridReplacement

        public void ShouldResolveHybridReplacement()
        {
            var container = new Container();
            container.Register<InterfaceA, ClassA1>(Lifecycle.HttpContextOrThreadLocal);

            var x = container.With<InterfaceA>(new ClassA2()).Resolve<InterfaceA>();

            Assert.IsInstanceOf<ClassA2>(x);
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:9,代码来源:With.cs

示例5: OriginalContainerShouldBeUnaffected

        public void OriginalContainerShouldBeUnaffected()
        {
            var container = new Container();
            container.Register<InterfaceA, ClassA1>();

            var x = container.With<InterfaceA>(new ClassA2()).Resolve<InterfaceA>();
            var y = container.Resolve<InterfaceA>();

            Assert.IsInstanceOf<ClassA1>(y);
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:10,代码来源:With.cs

示例6: ContainerShouldBeResolvable

        public void ContainerShouldBeResolvable()
        {
            var container = new Container();
            container.Register<InterfaceA, ClassA1>();

            var x = container.With<InterfaceA>(new ClassA2()).Resolve<InterfaceA>();
            var y = container.Resolve<IContainer>();
            var z = container.Resolve<IContainer>();

            Assert.IsInstanceOf<IContainer>(y);
            Assert.AreSame(y, z);
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:12,代码来源:With.cs

示例7: It_should_observe_keys

 public void It_should_observe_keys()
 {
     using (var container = new Container(cfg =>
                                       {
                                           cfg.For<IService>().Use<Service>();
                                           cfg.For<Thingy>().Use<Thingy>();
                                       }))
     {
         var service = new Service();
         var thingy = container.With("service").EqualTo(service).GetAllInstances<Thingy>().First();
         thingy.Service.ShouldBeTheSameAs(service);
     }
 }
开发者ID:smerrell,项目名称:structuremap,代码行数:13,代码来源:GetAllInstancesShouldObserveKeys.cs

示例8: Processes_WhenCalledMultipleTimes_RegistersEachHandlerType

        public void Processes_WhenCalledMultipleTimes_RegistersEachHandlerType()
        {
            const string instanceName = "empty";
            var handlerCache = new HandlerCache();
            handlerCache.Set(0);

            var sut = new Registry();

            sut.Register(instanceName)
                .Processes<CounterHandler>()
                .Processes<CounterHandler>();

            var container = new Container(sut);

            HandlerProcessor processor = container.With(handlerCache).GetInstance<HandlerProcessor>(instanceName);

            processor.Process();

            Assert.AreEqual(2, handlerCache.Get(typeof(int)));
        }
开发者ID:sullivac,项目名称:handlers,代码行数:20,代码来源:HandlerRegistrationTest.cs

示例9: Processes_WhenHandlerTypeHasProcessMethod_RegistersHandlerType

        public void Processes_WhenHandlerTypeHasProcessMethod_RegistersHandlerType()
        {
            const string instanceName = "empty";
            var handlerCache = new HandlerCache();

            var sut = new Registry();

            sut.Register(instanceName)
                .Processes<EmptyHandler>();

            var container = new Container(sut);

            HandlerProcessor processor = container.With(handlerCache).GetInstance<HandlerProcessor>(instanceName);

            processor.Process();

            Assert.IsTrue(container.Model.For<HandlerProcessor>().HasImplementations(), "Missing implementations.");
            Assert.IsNotNull(container.Model.Find<HandlerProcessor>(instanceName));
            Assert.AreEqual("message", handlerCache.Get(typeof(string)));
        }
开发者ID:sullivac,项目名称:handlers,代码行数:20,代码来源:HandlerRegistrationTest.cs

示例10: supply_defaults_by_generic

        public void supply_defaults_by_generic()
        {
            var container = new Container(x => {
                x.For<IWidget>().Use<BWidget>();
                x.For<IService>().Use<AService>();
            });

            var widget = new BWidget();
            var service = new BService();

            var guyWithWidgetAndService = container
                .With<IWidget>(widget)
                .With<IService>(service)
                .GetInstance<GuyWithWidgetAndService>();

            guyWithWidgetAndService
                .Widget.ShouldBeTheSameAs(widget);

            guyWithWidgetAndService
                .Service.ShouldBeTheSameAs(service);
        }
开发者ID:e-tobi,项目名称:structuremap,代码行数:21,代码来源:explicit_arguments.cs

示例11: use_explicit_type_arguments_with_custom_instance

        public void use_explicit_type_arguments_with_custom_instance()
        {
            var container =
                new Container(x => { x.For<ClassWithNoArgs>().Use(new SpecialInstance()); });

            var address = new Address();

            container.With(address).GetInstance<ClassWithNoArgs>()
                .TheAddress.ShouldBeTheSameAs(address);
        }
开发者ID:smerrell,项目名称:structuremap,代码行数:10,代码来源:TestExplicitArguments.cs

示例12: pass_explicit_service_into_all_instances_and_retrieve_without_generics

        public void pass_explicit_service_into_all_instances_and_retrieve_without_generics()
        {
            // The Container is constructed with 2 instances
            // of TradeView
            var container = new Container(r =>
            {
                r.For<TradeView>().Use<TradeView>();
                r.For<TradeView>().Add<SecuredTradeView>();
            });

            var theTrade = new Trade();

            var views = container.With(theTrade).GetAllInstances(typeof (TradeView))
                .OfType<TradeView>();

            views.ElementAt(0).Trade.ShouldBeTheSameAs(theTrade);
            views.ElementAt(1).Trade.ShouldBeTheSameAs(theTrade);
        }
开发者ID:smerrell,项目名称:structuremap,代码行数:18,代码来源:TestExplicitArguments.cs

示例13: use_a_type_that_is_not_part_of_the_constructor_in_the_with

 public void use_a_type_that_is_not_part_of_the_constructor_in_the_with()
 {
     var container = new Container();
     container.With(new Address()).GetInstance<ClassWithNoArgs>()
         .ShouldBeOfType<ClassWithNoArgs>();
 }
开发者ID:smerrell,项目名称:structuremap,代码行数:6,代码来源:TestExplicitArguments.cs

示例14: Explicit_services_are_used_throughout_the_object_graph

        public void Explicit_services_are_used_throughout_the_object_graph()
        {
            var theTrade = new Trade();

            IContainer container = new Container(r =>
            {
                r.For<IView>().Use<TradeView>();
                r.For<Node>().Use<TradeNode>();
            });

            var command = container.With(theTrade).GetInstance<Command>();

            command.Trade.ShouldBeTheSameAs(theTrade);
            command.Node.IsType<TradeNode>().Trade.ShouldBeTheSameAs(theTrade);
            command.View.IsType<TradeView>().Trade.ShouldBeTheSameAs(theTrade);
        }
开发者ID:smerrell,项目名称:structuremap,代码行数:16,代码来源:TestExplicitArguments.cs

示例15: Fill_in_argument_by_type

        public void Fill_in_argument_by_type()
        {
            var container = new Container(x => { x.For<IView>().Use<View>(); });

            var theNode = new SpecialNode();
            var theTrade = new Trade();

            var command = container
                .With(typeof (Node), theNode)
                .With(theTrade)
                .GetInstance<Command>();

            command.View.ShouldBeOfType<View>();
            theNode.ShouldBeTheSameAs(command.Node);
            theTrade.ShouldBeTheSameAs(command.Trade);
        }
开发者ID:smerrell,项目名称:structuremap,代码行数:16,代码来源:TestExplicitArguments.cs


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