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


C# DefaultKernel.Resolve方法代码示例

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


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

示例1: Application_Start

 protected void Application_Start(object sender, EventArgs e) {
     var kernel = new DefaultKernel();
     kernel.Register(Component.For<HttpContextBase>()
                         .LifeStyle.Transient
                         .UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
     kernel.Register(Component.For<SomeService>()
         .LifeStyle.HybridPerWebRequestTransient());
     kernel.Resolve<SomeService>();
 }
开发者ID:kujotx,项目名称:Castle.Windsor.Lifestyles,代码行数:9,代码来源:Global.asax.cs

示例2: tt

        public void tt()
        {
            var kernel = new DefaultKernel();
            kernel.Register(AllTypes.Pick()
                                   .FromAssembly(Assembly.GetExecutingAssembly())
                                   .WithService.FirstInterface());

            kernel.Resolve<ISomeInterface>();
        }
开发者ID:ruanzx,项目名称:mausch,代码行数:9,代码来源:RegTests.cs

示例3: Kernel_should_select_ctor_with_available_dependencies

 public void Kernel_should_select_ctor_with_available_dependencies()
 {
     var kernel = new DefaultKernel();
     kernel.AddComponent<Service>();
     kernel.AddComponent<ComponentX>();
     kernel.AddComponent<ComponentY>();
     var service = kernel.Resolve<Service>();
     Assert.IsNull(service.A);
     Assert.IsNotNull(service.X);
     Assert.IsNotNull(service.Y);
 }
开发者ID:ruanzx,项目名称:mausch,代码行数:11,代码来源:MultipleConstructorsAgain.cs

示例4: DoesNotResolveArraysByDefault

        public void DoesNotResolveArraysByDefault()
        {
            var kernel = new DefaultKernel();

            kernel.Register(
                Component.For<Thing>(),
                Component.For<ISubThing>().ImplementedBy<First>(),
                Component.For<ISubThing>().ImplementedBy<Second>(),
                Component.For<ISubThing>().ImplementedBy<Third>()
                );

            var thing = kernel.Resolve<Thing>();
        }
开发者ID:somlea-george,项目名称:sutekishop,代码行数:13,代码来源:ArrayResolverTests.cs

示例5: SetUp

		public void SetUp()
		{
			kernel = new DefaultKernel();

			kernel.AddFacility<StartableFacility>();

			kernel.Register(
				Component.For<StartableDisposableAndInitializableComponent>()
					.LifeStyle.Transient
				);

			component = kernel.Resolve<StartableDisposableAndInitializableComponent>();
			component.DoSomething();
			kernel.ReleaseComponent(component);

			calledMethods = component.calledMethods;
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:17,代码来源:IoC_113.cs

示例6: ShouldResolveArrayOfDependencies

        public void ShouldResolveArrayOfDependencies()
        {
            var kernel = new DefaultKernel();
            kernel.Resolver.AddSubResolver(new ArrayResolver(kernel));

            kernel.Register(
                Component.For<Thing>(),
                Component.For<ISubThing>().ImplementedBy<First>(),
                Component.For<ISubThing>().ImplementedBy<Second>(),
                Component.For<ISubThing>().ImplementedBy<Third>()
                );

            var thing = kernel.Resolve<Thing>();

            Assert.That(thing.SubThings.Count, Is.EqualTo(3));
            Assert.That(thing.SubThings[0], Is.InstanceOf(typeof(First)));
            Assert.That(thing.SubThings[1], Is.InstanceOf(typeof(Second)));
            Assert.That(thing.SubThings[2], Is.InstanceOf(typeof(Third)));
        }
开发者ID:somlea-george,项目名称:sutekishop,代码行数:19,代码来源:ArrayResolverTests.cs

示例7: Three_level_hierarchy

		public void Three_level_hierarchy([Values(0, 1, 2)] int parentComponentContainer,
		                                  [Values(0, 1, 2)] int childComponentContainer)
		{
			var subKernel = new DefaultKernel();
			var subSubKernel = new DefaultKernel();
			Kernel.AddChildKernel(subKernel);
			subKernel.AddChildKernel(subSubKernel);
			var containers = new[]
			{
				Kernel,
				subKernel,
				subSubKernel
			};

			containers[parentComponentContainer].Register(Component.For<UsesSimpleComponent1>());
			containers[childComponentContainer].Register(Component.For<SimpleComponent1>());

			subSubKernel.Resolve<UsesSimpleComponent1>();
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:19,代码来源:SubContainersTestCase.cs

示例8: Parent_component_will_NOT_have_dependencies_from_child

		public void Parent_component_will_NOT_have_dependencies_from_child()
		{
			Kernel.Register(Component.For<DefaultTemplateEngine>(),
			                Component.For<DefaultSpamService>());

			var child = new DefaultKernel();
			Kernel.AddChildKernel(child);

			child.Register(Component.For<DefaultMailSenderService>());

			var spamservice = child.Resolve<DefaultSpamService>();

			Assert.IsNotNull(spamservice);
			Assert.IsNotNull(spamservice.TemplateEngine);
			Assert.IsNull(spamservice.MailSender);
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:16,代码来源:SubContainersTestCase.cs

示例9: Singleton_withNonSingletonDependencies_doesNotReResolveDependencies

		public void Singleton_withNonSingletonDependencies_doesNotReResolveDependencies()
		{
			Kernel.Register(Component.For(typeof(DefaultSpamService)).Named("spamservice"));
			Kernel.Register(Component.For(typeof(DefaultMailSenderService)).Named("mailsender"));

			var subkernel1 = new DefaultKernel();
			subkernel1.Register(Component.For(typeof(DefaultTemplateEngine)).Named("templateengine"));
			Kernel.AddChildKernel(subkernel1);

			var subkernel2 = new DefaultKernel();
			subkernel2.Register(Component.For(typeof(DefaultTemplateEngine)).Named("templateengine")
				                    .LifeStyle.Is(LifestyleType.Transient));
			Kernel.AddChildKernel(subkernel2);

			var templateengine1 = subkernel1.Resolve<DefaultTemplateEngine>("templateengine");
			var spamservice1 = subkernel1.Resolve<DefaultSpamService>("spamservice");

			Assert.IsNull(spamservice1.TemplateEngine);

			var templateengine2 = subkernel2.Resolve<DefaultTemplateEngine>("templateengine");
			var spamservice2 = subkernel2.Resolve<DefaultSpamService>("spamservice");

			Assert.AreSame(spamservice1, spamservice2);
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:24,代码来源:SubContainersTestCase.cs

示例10: DependenciesSatisfiedAmongContainersUsingEvents

		public void DependenciesSatisfiedAmongContainersUsingEvents()
		{
			IKernel subkernel = new DefaultKernel();

			subkernel.Register(Component.For(typeof(DefaultSpamServiceWithConstructor)).Named("spamservice"));

			Kernel.Register(Component.For(typeof(DefaultMailSenderService)).Named("mailsender"));
			Kernel.Register(Component.For(typeof(DefaultTemplateEngine)).Named("templateengine"));

			Kernel.AddChildKernel(subkernel);

			var spamservice =
				subkernel.Resolve<DefaultSpamServiceWithConstructor>("spamservice");

			Assert.IsNotNull(spamservice);
			Assert.IsNotNull(spamservice.MailSender);
			Assert.IsNotNull(spamservice.TemplateEngine);
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:18,代码来源:SubContainersTestCase.cs

示例11: Requesting_parent_component_with_child_dependency_from_child_component

		public void Requesting_parent_component_with_child_dependency_from_child_component()
		{
			var subkernel = new DefaultKernel();
			Kernel.AddChildKernel(subkernel);

			Kernel.Register(Component.For<UsesSimpleComponent1>());
			subkernel.Register(Component.For<SimpleComponent1>());

			subkernel.Resolve<UsesSimpleComponent1>();
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:10,代码来源:SubContainersTestCase.cs

示例12: TestStartableCustomDependencies

		public void TestStartableCustomDependencies()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentCreated += OnStartableComponentStarted;

			kernel.AddFacility("startable", new StartableFacility());

			kernel.Register(
				Component.For<StartableComponentCustomDependencies>()
					.Named("a")
					.DependsOn(Property.ForKey("config").Eq(1))
				);
			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			var component = kernel.Resolve<StartableComponentCustomDependencies>("a");

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
开发者ID:HEskandari,项目名称:Castle.InversionOfControl,代码行数:23,代码来源:StartableFacilityTestCase.cs

示例13: ChildKernelOverloadsParentKernel2

		public void ChildKernelOverloadsParentKernel2()
		{
			var instance1 = new DefaultTemplateEngine();
			var instance2 = new DefaultTemplateEngine();

			IKernel subkernel = new DefaultKernel();
			Kernel.AddChildKernel(subkernel);

			// subkernel added first, then populated with overloaded components after

			Kernel.Register(Component.For<DefaultTemplateEngine>().Named("engine").Instance(instance2));
			Assert.AreEqual(instance2, Kernel.Resolve<DefaultTemplateEngine>("engine"));
			Assert.AreEqual(instance2, subkernel.Resolve<DefaultTemplateEngine>("engine"));

			subkernel.Register(Component.For<DefaultTemplateEngine>().Named("engine").Instance(instance1));
			Assert.AreEqual(instance1, subkernel.Resolve<DefaultTemplateEngine>("engine"));
			Assert.AreEqual(instance2, Kernel.Resolve<DefaultTemplateEngine>("engine"));
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:18,代码来源:SubContainersTestCase.cs

示例14: TestStartableWithRegisteredCustomDependencies

		public void TestStartableWithRegisteredCustomDependencies()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentCreated += OnStartableComponentStarted;

			kernel.AddFacility("startable", new StartableFacility());

			var dependencies = new Dictionary<string, object> { { "config", 1 } };
			kernel.Register(Component.For(typeof(StartableComponentCustomDependencies)).Named("a"));
			kernel.RegisterCustomDependencies(typeof(StartableComponentCustomDependencies), dependencies);

			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			var component = kernel.Resolve<StartableComponentCustomDependencies>("a");

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
开发者ID:HEskandari,项目名称:Castle.InversionOfControl,代码行数:22,代码来源:StartableFacilityTestCase.cs

示例15: Do_NOT_UseChildComponentsForParentDependenciesWhenRequestedFromChild

		public void Do_NOT_UseChildComponentsForParentDependenciesWhenRequestedFromChild()
		{
			IKernel subkernel = new DefaultKernel();

			Kernel.Register(Component.For(typeof(DefaultSpamService)).Named("spamservice").LifeStyle.Is(LifestyleType.Transient));
			Kernel.Register(Component.For(typeof(DefaultMailSenderService)).Named("mailsender"));
			Kernel.Register(Component.For(typeof(DefaultTemplateEngine)).Named("templateengine"));

			Kernel.AddChildKernel(subkernel);
			subkernel.Register(Component.For(typeof(DefaultTemplateEngine)).Named("templateengine"));

			var templateengine = Kernel.Resolve<DefaultTemplateEngine>("templateengine");
			var sub_templateengine = subkernel.Resolve<DefaultTemplateEngine>("templateengine");

			var spamservice = subkernel.Resolve<DefaultSpamService>("spamservice");
			Assert.AreNotEqual(spamservice.TemplateEngine, sub_templateengine);
			Assert.AreEqual(spamservice.TemplateEngine, templateengine);

			spamservice = Kernel.Resolve<DefaultSpamService>("spamservice");
			Assert.AreNotEqual(spamservice.TemplateEngine, sub_templateengine);
			Assert.AreEqual(spamservice.TemplateEngine, templateengine);
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:22,代码来源:SubContainersTestCase.cs


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