• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# DefaultKernel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: 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


示例3: 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


示例4: 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


示例5: SimpleUsage

		public void SimpleUsage()
		{
			IKernel kernel = new DefaultKernel();
			kernel.AddComponent("a", typeof(PoolableComponent1));

			PoolableComponent1 inst1 = kernel["a"] as PoolableComponent1;
			PoolableComponent1 inst2 = kernel["a"] as PoolableComponent1;

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

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

			PoolableComponent1 other1 = kernel["a"] as PoolableComponent1;
			PoolableComponent1 other2 = kernel["a"] as PoolableComponent1;

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

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

			kernel.ReleaseComponent(inst2);
			kernel.ReleaseComponent(inst1);
		}
开发者ID:ralescano,项目名称:castle,代码行数:26,代码来源:PooledLifestyleManagerTestCase.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: MaxSize

		public void MaxSize()
		{
			IKernel kernel = new DefaultKernel();
			kernel.AddComponent("a", typeof(PoolableComponent1));

			ArrayList instances = new ArrayList();

			instances.Add(kernel["a"] as PoolableComponent1);
			instances.Add(kernel["a"] as PoolableComponent1);
			instances.Add(kernel["a"] as PoolableComponent1);
			instances.Add(kernel["a"] as PoolableComponent1);
			instances.Add(kernel["a"] as PoolableComponent1);

			PoolableComponent1 other1 = kernel["a"] as PoolableComponent1;

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

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

			kernel.ReleaseComponent(other1);

			PoolableComponent1 other2 = kernel["a"] as PoolableComponent1;
			Assert.IsNotNull(other2);
			Assert.IsTrue(other1 != other2);
			Assert.IsTrue(instances.Contains(other2));

			kernel.ReleaseComponent(other2);
		}
开发者ID:ralescano,项目名称:castle,代码行数:32,代码来源:PooledLifestyleManagerTestCase.cs


示例8: AddingComponentToRootKernelWhenChildKernelHasStartableFacility

 public void AddingComponentToRootKernelWhenChildKernelHasStartableFacility()
 {
     IKernel kernel = new DefaultKernel();
     IKernel childKernel = new DefaultKernel();
     kernel.AddChildKernel(childKernel);
     childKernel.AddFacility("StartableFacility", new StartableFacility());
     kernel.AddComponent("string", typeof(String)); // exception here
 }
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:8,代码来源:IoC-95.cs


示例9: AddingComponentToRootKernelWhenChildKernelHasStartableFacility

		public void AddingComponentToRootKernelWhenChildKernelHasStartableFacility()
		{
			IKernel kernel = new DefaultKernel();
			IKernel childKernel = new DefaultKernel();
			kernel.AddChildKernel(childKernel);
			childKernel.AddFacility(new StartableFacility());
			kernel.Register(Component.For(typeof (A)).Named("string")); // exception here
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:8,代码来源:IoC-95.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: Init

		public void Init()
		{
			kernel = new DefaultKernel();
			kernel.Register(Component.For(typeof(CompA)).Named("compa"));
			kernel.Register(Component.For(typeof(CompB)).Named("compb"));

			deps = new Dictionary<string, object>();
			deps.Add("cc", new CompC(12));
			deps.Add("myArgument", "ernst");
		}
开发者ID:vbedegi,项目名称:Castle.InversionOfControl,代码行数:10,代码来源:RuntimeParametersTestCase.cs


示例12: 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


示例13: 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


示例14: 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


示例15: 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


示例16: ContainerShouldUseFirstRegisteredDependencyOfTypeByDefault_EmailRegisteredFirst

		public void ContainerShouldUseFirstRegisteredDependencyOfTypeByDefault_EmailRegisteredFirst()
		{
			IKernel kernel = new DefaultKernel();
			kernel.AddComponent("email", typeof(IAlarmSender), typeof(EmailSender));
			kernel.AddComponent("sms", typeof(IAlarmSender), typeof(SmsSender));

			kernel.AddComponent("generator", typeof(AlarmGenerator));

			AlarmGenerator gen = (AlarmGenerator)kernel["generator"];
			Assert.AreEqual(typeof(EmailSender), gen.Sender.GetType());
		}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:11,代码来源:DependencyResolvingTestCase.cs


示例17: 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


示例18: 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


示例19: ChildDependenciesIsSatisfiedEvenWhenComponentTakesLongToBeAddedToParentContainer

		public void ChildDependenciesIsSatisfiedEvenWhenComponentTakesLongToBeAddedToParentContainer()
		{
			DefaultKernel container = new DefaultKernel();
			DefaultKernel childContainer = new DefaultKernel();

			container.AddChildKernel(childContainer);
			((IKernel)childContainer).Register(Component.For(typeof(UsesIEmptyService)).Named("component"));

			((IKernel)container).Register(Component.For(typeof(IEmptyService)).ImplementedBy(typeof(EmptyService)).Named("service1"));

			UsesIEmptyService comp = (UsesIEmptyService) childContainer[typeof(UsesIEmptyService)];
		}
开发者ID:gschuager,项目名称:Castle.Windsor,代码行数:12,代码来源:SubContainersTestCase.cs


示例20: ChildDependenciesIsSatisfiedEvenWhenComponentTakesLongToBeAddedToParentContainer

		public void ChildDependenciesIsSatisfiedEvenWhenComponentTakesLongToBeAddedToParentContainer()
		{
			DefaultKernel container = new DefaultKernel();
			DefaultKernel childContainer = new DefaultKernel();

			container.AddChildKernel(childContainer);
			childContainer.AddComponent("component", typeof(Component));

			container.AddComponent("service1", typeof(IService), typeof(Service));

			Component comp = (Component) childContainer[typeof(Component)];
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:12,代码来源:SubContainersTestCase.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DefaultObject类代码示例发布时间:2022-05-24
下一篇:
C# DefaultIntellisenseProvider类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap