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


C# Container.Inject方法代码示例

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


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

示例1: ShouldRemoveExecutionContextInstanceOnly

        public void ShouldRemoveExecutionContextInstanceOnly()
        {
            var instance1 = new TestClass();
            var instance2 = new TestClass();

            var container = new Container();
            container.Inject<TestInterface>(instance1, Lifecycle.HttpContextOrExecutionContextLocal);

            TestInterface[] thread2ResolvedTestClasses = null;
            bool thread2HasRegistration = true;
            ExecutionContext.SuppressFlow();
            var thread2 = new Thread(() =>
            {
                container.Inject<TestInterface>(instance2, Lifecycle.HttpContextOrExecutionContextLocal);

                thread2ResolvedTestClasses = container.ResolveAll<TestInterface>().ToArray();

                container.RemoveInstancesOf<TestInterface>(Lifecycle.HttpContextOrExecutionContextLocal);

                thread2HasRegistration = container.HasRegistrationFor<TestInterface>();
            });

            thread2.Start();
            thread2.Join(1000);
            ExecutionContext.RestoreFlow();
            Assert.IsFalse(thread2HasRegistration);
            Assert.AreEqual(1, thread2ResolvedTestClasses.Length);

            Assert.AreEqual(instance1, container.Resolve<TestInterface>());
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:30,代码来源:RemovingInstances.cs

示例2: ShouldResolveInjectedOverInjected

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

            container.Register<TestInterface, TestClass>();

            var injector1 = new TestClass2();
            var injector2 = new TestClass2();
            container.Inject<TestInterface>(injector1);
            container.Inject<TestInterface>(injector2, injectionBehaviour: InjectionBehaviour.Override);

            Assert.AreSame(injector2, container.Resolve<TestInterface>());
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:13,代码来源:InjectingInstances.cs

示例3: OnEndStart_ScheduleEvery_Called

        public void OnEndStart_ScheduleEvery_Called()
        {
            var fakeBus = MockRepository.GenerateStub<IServiceBus>();
            var fakeScheduler = MockRepository.GenerateStub<IScheduler>();
            var fakeContainer = new Container();
            fakeContainer.Inject<IServiceBus>(fakeBus);
            fakeContainer.Inject<IScheduler>(fakeScheduler);
            var testObject = new ClientBootstrapperTest(fakeContainer);

            testObject.OnEndStart();

            fakeScheduler.AssertWasCalled(x => x.Every(
                Arg<TimeSpan>.Is.Anything, Arg<Action>.Is.NotNull));
        }
开发者ID:erictummers,项目名称:RhinoServiceBusDemo,代码行数:14,代码来源:ClientBootstrapperTest.cs

示例4: ShouldRemoveInstances3

        public void ShouldRemoveInstances3()
        {
            var container = new Container();
            var class1 = new ClassA1();
            var class2 = new ClassA1();

            container.Inject(class1, Lifecycle.HttpContextOrThreadLocal);

            container.RemoveAllInstancesWithLifecycle(Lifecycle.HttpContextOrThreadLocal);

            container.Inject(class2, Lifecycle.HttpContextOrThreadLocal);

            var classA1 = container.Resolve<ClassA1>();
            Assert.AreSame(class2, classA1);
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:15,代码来源:RemovingRegistrations.cs

示例5: Start

        public bool Start(HostControl hostControl)
        {
            var container = new Container(cfg => cfg.Scan(scan =>
                {
                    scan.TheCallingAssembly();
                    scan.AssembliesFromApplicationBaseDirectory();
                    scan.AddAllTypesOf(typeof (IConsumer));
                }));

            try
            {
                _Bus = ServiceBusFactory.New(sbc =>
                    {
                        sbc.UseRabbitMq();
                        sbc.ReceiveFrom(ConfigurationManager.AppSettings["RabbitMQEndPoint"]);
                        sbc.Subscribe(x => x.LoadFrom(container));
                        sbc.Validate();
                    });

                container.Inject(_Bus);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return false;
            }
            return true;
        }
开发者ID:RendaniTshinakaho,项目名称:Cuttlefish,代码行数:28,代码来源:ProjectionService.cs

示例6: SetUp

        public void SetUp()
        {
            FubuTransport.Reset();

            // Need to do something about this.  Little ridiculous
            var settings = new BusSettings
            {
                Downstream = "lq.tcp://localhost:2020/downstream".ToUri()
            };

            var container = new Container();
            container.Inject(settings);

            _runtime = FubuTransport.For<DelayedRegistry>().StructureMap(container)
                                       .Bootstrap();

            theServiceBus = _runtime.Factory.Get<IServiceBus>();
            _runtime.Factory.Get<IPersistentQueues>().ClearAll();

            theClock = _runtime.Factory.Get<ISystemTime>().As<SettableClock>();

            message1 = new OneMessage();
            message2 = new OneMessage();
            message3 = new OneMessage();
            message4 = new OneMessage();

            theServiceBus.DelaySend(message1, theClock.UtcNow().AddHours(1));
            theServiceBus.DelaySend(message2, theClock.UtcNow().AddHours(1));
            theServiceBus.DelaySend(message3, theClock.UtcNow().AddHours(2));
            theServiceBus.DelaySend(message4, theClock.UtcNow().AddHours(2));
        }
开发者ID:JackGilliam1,项目名称:FubuTransportation,代码行数:31,代码来源:Full_end_to_end_delayed_message_processing_with_Lightning_Queues.cs

示例7: SetUp

        public void SetUp()
        {
            container = new Container(new RavenDbRegistry());
            container.Inject(new RavenDbSettings { RunInMemory = true });

            theReset = container.GetInstance<IPersistenceReset>();
            theUnitOfWork = new RavenUnitOfWork(container);
        }
开发者ID:kingreatwill,项目名称:fubumvc,代码行数:8,代码来源:RavenPersistenceResetTester.cs

示例8: FixtureSetUp

 public void FixtureSetUp()
 {
     container = new Container(new RavenDbRegistry());
     container.Inject(new RavenDbSettings
     {
         RunInMemory = true
     });
 }
开发者ID:DarthFubuMVC,项目名称:FubuPersistence,代码行数:8,代码来源:RavenTransactionTester.cs

示例9: ShouldRemoveInstances

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

            container.RemoveAllRegistrationsAndInstancesOf<InterfaceA>();

            Assert.AreEqual(0, container.ResolveAll<InterfaceA>().Count());
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:10,代码来源:RemovingRegistrations.cs

示例10: OnEndStart_SendSchedulerMessage_Scheduled

        public void OnEndStart_SendSchedulerMessage_Scheduled()
        {
            var fakeBus = MockRepository.GenerateStub<IServiceBus>();
            var fakeScheduler = MockRepository.GenerateStub<IScheduler>();
            var fakeContainer = new Container();
            fakeContainer.Inject<IServiceBus>(fakeBus);
            fakeContainer.Inject<IScheduler>(fakeScheduler);
            var testObject = new ClientBootstrapperTest(fakeContainer);
            testObject.OnEndStart();

            // get the action from the arguments
            var args = fakeScheduler.GetArgumentsForCallsMadeOn(x => x.Every(
                Arg<TimeSpan>.Is.Anything, Arg<Action>.Is.NotNull));
            var action = args[0][1] as Action;
            // execute the action
            action();

            fakeBus.AssertWasCalled(x => x.Send(Arg<SchedulerMessage>.Is.NotNull));
        }
开发者ID:erictummers,项目名称:RhinoServiceBusDemo,代码行数:19,代码来源:ClientBootstrapperTest.cs

示例11: Container

        public void ContainerControllerFactory_CreateController_ReturnsExpectedTypeFromContainer_GivenContainerAndProperType()
        {
            var container = new Container();
            var controller = new ProperController();
            container.Inject<ProperController>(controller);
            var factory = new TestContainerControllerFactory(new ContainerResolver(container));
            factory.GetControllerTypeDelegate = () => typeof(ProperController);

            Assert.Same(controller, factory.CreateController(null, ""));
        }
开发者ID:shibbard,项目名称:Multi-tenancy-Sample,代码行数:10,代码来源:ContainerControllerFactoryTests.cs

示例12: ShouldntHaveRegistrations

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

            container.RemoveAllRegistrationsAndInstancesOf<InterfaceA>();

            Assert.IsFalse(container.HasRegistrationFor<InterfaceA>());
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:11,代码来源:RemovingRegistrations.cs

示例13: CreateContainer

		public static IContainer CreateContainer(string sagaDb = null)
		{
			sagaDb = sagaDb ?? HttpContext.Current.Server.MapPath("~/App_Data/saga_state.db");
			if (sagaDb == null) throw new ArgumentNullException("sagaDb");

			var endpointUri = "loopback://localhost/ScreenShotter.Web/";

			// FubuApplication "guides" the bootstrapping of the FubuMVC
			// application
			var container = new Container(x =>
				{
					x.For<ISessionFactory>()
						.Singleton()
						.Add(ctx =>
							{
								var config = Fluently.Configure()
									.Database(SQLiteConfiguration.Standard.UsingFile(sagaDb))
									.Mappings(m => m.FluentMappings.AddFromAssemblyOf<WebShotSagaMap>())
									.BuildConfiguration();
									
								new SchemaUpdate(config).Execute(true, true);

								return config.BuildSessionFactory();
							});

					x.For<ISagaRepository<WebShotSaga>>()
						.Singleton()
						.Use<NHibernateSagaRepository<WebShotSaga>>();

					x.ForConcreteType<WebShotSaga>();

					x.ForConcreteType<PostHandler>().Configure.Ctor<IEndpoint>()
						.Is(ctx => ctx.GetInstance<IServiceBus>().GetEndpoint(new Uri(endpointUri)));

					x.For<IServiceBus>().Singleton();
				});

			var serviceBus = ServiceBusFactory.New(sbc =>
				{
					sbc.UseJsonSerializer();
					sbc.ReceiveFrom(endpointUri);
					sbc.Subscribe(x => x.LoadFrom(container));
				});

			PipelineViewer.Trace(serviceBus.InboundPipeline);

			//PipelineViewer.Trace(serviceBus.OutboundPipeline);

			container.Inject(serviceBus);
			return container;
		}
开发者ID:haf,项目名称:Code4Fun.WebShotter,代码行数:51,代码来源:Bootstrapper.cs

示例14: Application_Start

        protected void Application_Start(object sender, EventArgs e)
        {
            var container = new Container();
            FubuApplication.For<HarnessRegistry>().StructureMap(container).Bootstrap();

            var membership = new InMemoryMembershipRepository();
            membership.Add(new UserInfo
            {
                UserName = "jeremy",
                Password = "carthage"
            });

            container.Inject<IMembershipRepository>(membership);
        }
开发者ID:RobertTheGrey,项目名称:FubuMVC.Authentication,代码行数:14,代码来源:Global.asax.cs

示例15: ContainerControllerFactory_CreateController_DoesntSetActionInvoker_WhenOfCorrectType

        public void ContainerControllerFactory_CreateController_DoesntSetActionInvoker_WhenOfCorrectType()
        {
            var container = new Container();
            var containerResolver = new ContainerResolver(container);
            var controller = new ProperController();
            var actionInvoker = new ContainerControllerActionInvoker(containerResolver);

            controller.ActionInvoker = actionInvoker;
            container.Inject<ProperController>(controller);
            var factory = new TestContainerControllerFactory(containerResolver);
            factory.GetControllerTypeDelegate = () => typeof(ProperController);

            Assert.Same(actionInvoker, (factory.CreateController(null, "") as ProperController).ActionInvoker);
        }
开发者ID:shibbard,项目名称:Multi-tenancy-Sample,代码行数:14,代码来源:ContainerControllerFactoryTests.cs


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