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


C# DefaultKernel.Resolve方法代码示例

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


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

示例1: SimpleUsage

		public void SimpleUsage()
		{
			IKernel kernel = new DefaultKernel();
			kernel.Register(Component.For(typeof(PoolableComponent1)).Named("a"));

			PoolableComponent1 inst1 = kernel.Resolve<PoolableComponent1>("a");
			PoolableComponent1 inst2 = kernel.Resolve<PoolableComponent1>("a");

			Assert.IsNotNull(inst1);
			Assert.IsNotNull(inst2);

			kernel.ReleaseComponent(inst2);
			kernel.ReleaseComponent(inst1);

			PoolableComponent1 other1 = kernel.Resolve<PoolableComponent1>("a");
			PoolableComponent1 other2 = kernel.Resolve<PoolableComponent1>("a");

			Assert.IsNotNull(other1);
			Assert.IsNotNull(other2);

			Assert.AreSame(inst1, other1);
			Assert.AreSame(inst2, other2);

			kernel.ReleaseComponent(inst2);
			kernel.ReleaseComponent(inst1);
		}
开发者ID:vbedegi,项目名称:Castle.InversionOfControl,代码行数:26,代码来源:PooledLifestyleManagerTestCase.cs

示例2: TransientMultipleConstructorNonValueTypeTest

		public void TransientMultipleConstructorNonValueTypeTest()
		{
			DefaultKernel container = new DefaultKernel();
			((IKernel)container).Register(Component.For(typeof(FooBarNonValue)).Named("FooBar"));
			Tester1 bla1 = new Tester1("FOOBAR");
			Tester2 bla2 = new Tester2(666);

			var arguments1 = new Dictionary<object, object>();
			arguments1.Add("test1", bla1);

			var arguments2 = new Dictionary<object, object>();
			arguments2.Add("test2", bla2);

			object a = container.Resolve(typeof(FooBarNonValue), arguments1);
			object b = container.Resolve(typeof(FooBarNonValue), arguments2);

			Assert.AreNotSame(a, b, "A should not be B");

			// multi resolve test

			a = container.Resolve(typeof(FooBarNonValue), arguments1);
			b = container.Resolve(typeof(FooBarNonValue), arguments2);

			Assert.AreNotSame(a, b, "A should not be B");
		}
开发者ID:dohansen,项目名称:Windsor,代码行数:25,代码来源:TransientMultiConstructorTestCase.cs

示例3: TransientMultipleConstructorNonValueTypeTest

		public void TransientMultipleConstructorNonValueTypeTest()
		{
			DefaultKernel container = new DefaultKernel();
			container.AddComponent("FooBar", typeof(FooBarNonValue));
			Tester1 bla1 = new Tester1("FOOBAR");
			Tester2 bla2 = new Tester2(666);

			Hashtable arguments1 = new Hashtable();
			arguments1.Add("test1", bla1);

			Hashtable arguments2 = new Hashtable();
			arguments2.Add("test2", bla2);

			object a = container.Resolve(typeof(FooBarNonValue), arguments1);
			object b = container.Resolve(typeof(FooBarNonValue), arguments2);

			Assert.AreNotSame(a, b, "A should not be B");

			// multi resolve test

			a = container.Resolve(typeof(FooBarNonValue), arguments1);
			b = container.Resolve(typeof(FooBarNonValue), arguments2);

			Assert.AreNotSame(a, b, "A should not be B");
		}
开发者ID:ralescano,项目名称:castle,代码行数:25,代码来源:TransientMultiConstructorTestCase.cs

示例4: No_context_uses_transient

 public void No_context_uses_transient() {
     using (var k = new DefaultKernel()) {
         k.Register(Component.For<Dummy>().LifeStyle.HybridPerWebRequestTransient());
         var d1 = k.Resolve<Dummy>();
         Assert.IsNotNull(d1);
         var d2 = k.Resolve<Dummy>();
         Assert.IsNotNull(d2);
         Assert.AreNotSame(d1, d2);
     }
 }
开发者ID:kujotx,项目名称:Castle.Windsor.Lifestyles,代码行数:10,代码来源:HybridPerWebRequestTransientTests.cs

示例5: TransientMultiConstructorTest

		public void TransientMultiConstructorTest()
		{
			DefaultKernel container = new DefaultKernel();
			container.AddComponent("FooBar", typeof(FooBar));

			Hashtable arguments1 = new Hashtable();
			arguments1.Add("integer", 1);

			Hashtable arguments2 = new Hashtable();
			arguments2.Add("datetime", DateTime.Now.AddDays(1));

			object a = container.Resolve(typeof(FooBar), arguments1);
			object b = container.Resolve(typeof(FooBar), arguments2);

			Assert.AreNotSame(a, b, "A should not be B");
		}
开发者ID:ralescano,项目名称:castle,代码行数:16,代码来源:TransientMultiConstructorTestCase.cs

示例6: Will_give_good_error_message_if_cannot_resolve_service_that_is_likely_decorated

        public void Will_give_good_error_message_if_cannot_resolve_service_that_is_likely_decorated()
        {
            DefaultKernel kernel = new DefaultKernel();
            kernel.Register(
                Component.For<IRepository>().ImplementedBy<Repository1>(),
                Component.For<IRepository>().ImplementedBy<DecoratedRepository2>()
                );
            try
            {
                kernel.Resolve<IRepository>();
            }
            catch (HandlerException e)
            {
                const string expectedMessage = @"Can't create component 'Castle.MicroKernel.Tests.ClassComponents.Repository1' as it has dependencies to be satisfied. 
Castle.MicroKernel.Tests.ClassComponents.Repository1 is waiting for the following dependencies: 

Services: 
- Castle.MicroKernel.Tests.ClassComponents.IRepository. 
  A dependency cannot be satisfied by itself, did you forget to add a parameter name to differentiate between the two dependencies? 
 
Castle.MicroKernel.Tests.ClassComponents.DecoratedRepository2 is registered and is matching the required service, but cannot be resolved.

Castle.MicroKernel.Tests.ClassComponents.DecoratedRepository2 is waiting for the following dependencies: 

Keys (components with specific keys)
- name which was not registered. 
";
                Assert.AreEqual(expectedMessage, e.Message);
            }
        }
开发者ID:ralescano,项目名称:castle,代码行数:30,代码来源:DecoratorsTestCase.cs

示例7: TransientMultiConstructorTest

		public void TransientMultiConstructorTest()
		{
			DefaultKernel container = new DefaultKernel();
			((IKernel)container).Register(Component.For(typeof(FooBar)).Named("FooBar"));

			var arguments1 = new Dictionary<object, object>();
			arguments1.Add("integer", 1);

			var arguments2 = new Dictionary<object, object>();
			arguments2.Add("datetime", DateTime.Now.AddDays(1));

			object a = container.Resolve(typeof(FooBar), arguments1);
			object b = container.Resolve(typeof(FooBar), arguments2);

			Assert.AreNotSame(a, b, "A should not be B");
		}
开发者ID:dohansen,项目名称:Windsor,代码行数:16,代码来源:TransientMultiConstructorTestCase.cs

示例8: PerWebRequestLifestyleManagerTest

        public void PerWebRequestLifestyleManagerTest() {
            var tw = new StringWriter();
            var wr = new SimpleWorkerRequest("/", Directory.GetCurrentDirectory(), "default.aspx", null, tw);
            var module = new PerWebRequestLifestyleModule();

            var ctx = HttpModuleRunner.GetContext(wr, new[] { module });
            HttpContext.Current = ctx.Key;

            using (var kernel = new DefaultKernel()) {
                kernel.Register(Component.For<object>().LifeStyle.PerWebRequest);
                var instance1 = kernel.Resolve<object>();
                Assert.IsNotNull(instance1);
                var instance2 = kernel.Resolve<object>();
                Assert.IsNotNull(instance2);
                Assert.AreSame(instance1, instance2);
            }
        }
开发者ID:gschuager,项目名称:Castle.Windsor.Lifestyles,代码行数:17,代码来源:HybridPerWebRequestTransientLifestyleManagerTests.cs

示例9: MaxSize

		public void MaxSize()
		{
			IKernel kernel = new DefaultKernel();
			kernel.Register(Component.For(typeof(PoolableComponent1)).Named("a"));

			var instances = new List<PoolableComponent1>
			{
				kernel.Resolve<PoolableComponent1>("a"),
				kernel.Resolve<PoolableComponent1>("a"),
				kernel.Resolve<PoolableComponent1>("a"),
				kernel.Resolve<PoolableComponent1>("a"),
				kernel.Resolve<PoolableComponent1>("a")
			};

			PoolableComponent1 other1 = kernel.Resolve<PoolableComponent1>("a");

			Assert.IsNotNull(other1);
			Assert.IsTrue(!instances.Contains(other1));

			foreach (PoolableComponent1 inst in instances)
			{
				kernel.ReleaseComponent(inst);
			}

			kernel.ReleaseComponent(other1);

			PoolableComponent1 other2 = kernel.Resolve<PoolableComponent1>("a");
			Assert.IsNotNull(other2);
			Assert.IsTrue(other1 != other2);
			Assert.IsTrue(instances.Contains(other2));

			kernel.ReleaseComponent(other2);
		}
开发者ID:vbedegi,项目名称:Castle.InversionOfControl,代码行数:33,代码来源:PooledLifestyleManagerTestCase.cs

示例10: AddingDependencyToServiceWithCustomDependency

		public void AddingDependencyToServiceWithCustomDependency()
		{
			var kernel = new DefaultKernel();
			kernel.Register(Component.For<NeedClassWithCustomerDependency>(),
			                Component.For<HasCustomDependency>().DependsOn(new Dictionary<object, object> { { "name", new CompA() } }));

			Assert.AreEqual(HandlerState.Valid, kernel.GetHandler(typeof(HasCustomDependency)).CurrentState);
			Assert.IsNotNull(kernel.Resolve(typeof(NeedClassWithCustomerDependency)));
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:9,代码来源:RuntimeParametersTestCase.cs

示例11: DefaultKernel

 public void Will_give_good_error_message_if_cannot_resolve_service_that_is_likely_decorated_when_there_are_multiple_service()
 {
     DefaultKernel kernel = new DefaultKernel();
     kernel.Register(
         Component.For<IRepository>().ImplementedBy<Repository1>(),
         Component.For<IRepository>().ImplementedBy<DecoratedRepository2>().Named("foo"),
         Component.For<IRepository>().ImplementedBy<Repository1>().Named("bar")
         );
     kernel.Resolve<IRepository>();
 }
开发者ID:ralescano,项目名称:castle,代码行数:10,代码来源:DecoratorsTestCase.cs

示例12: Should_ignore_reference_to_itself

 public void Should_ignore_reference_to_itself()
 {
     DefaultKernel kernel = new DefaultKernel();
     kernel.Register(
         Component.For<IRepository>().ImplementedBy<Repository1>(),
         Component.For<IRepository>().ImplementedBy<DecoratedRepository>()
         );
     Repository1 repos = (Repository1)kernel.Resolve<IRepository>();
     Assert.IsInstanceOfType(typeof(DecoratedRepository), repos.InnerRepository);
 }
开发者ID:ralescano,项目名称:castle,代码行数:10,代码来源:DecoratorsTestCase.cs

示例13: ContainerShouldUseFirstRegisteredDependencyOfTypeByDefault_SmsRegisteredFirst

		public void ContainerShouldUseFirstRegisteredDependencyOfTypeByDefault_SmsRegisteredFirst()
		{
			IKernel kernel = new DefaultKernel();
			kernel.Register(Component.For(typeof(IAlarmSender)).ImplementedBy(typeof(SmsSender)).Named("sms"));
			kernel.Register(Component.For(typeof(IAlarmSender)).ImplementedBy(typeof(EmailSender)).Named("email"));

			kernel.Register(Component.For(typeof(AlarmGenerator)).Named("generator"));

			var gen = kernel.Resolve<AlarmGenerator>("generator");
			Assert.AreEqual(typeof(SmsSender), gen.Sender.GetType());
		}
开发者ID:vbedegi,项目名称:Castle.InversionOfControl,代码行数:11,代码来源:DependencyResolvingTestCase.cs

示例14: UsingPropertyWithPrivateSetter

        public void UsingPropertyWithPrivateSetter()
        {
            IKernel container = new DefaultKernel();

            container.AddComponent("service1", typeof(IService1), typeof(Service1));
            container.AddComponent("service2", typeof(IService2), typeof(Service2));

            Service2 service2 = (Service2)container.Resolve<IService2>();

            Assert.IsNull(service2.S,"Kernel should ignore private setter properties");
        }
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:11,代码来源:IoC-114.cs

示例15: UsingPropertyWithPrivateSetter

        public void UsingPropertyWithPrivateSetter()
        {
            IKernel container = new DefaultKernel();

            container.Register(Component.For(typeof(IService1)).ImplementedBy(typeof(Service1)).Named("service1"));
            container.Register(Component.For(typeof(IService2)).ImplementedBy(typeof(Service2)).Named("service2"));

            Service2 service2 = (Service2)container.Resolve<IService2>();

            Assert.IsNull(service2.S,"Kernel should ignore private setter properties");
        }
开发者ID:gschuager,项目名称:Castle.Windsor,代码行数:11,代码来源:IoC-114.cs


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