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


C# DefaultKernel.AddComponent方法代码示例

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


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

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

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

示例3: ComponentGraph

		public void ComponentGraph()
		{
			IKernel kernel = new DefaultKernel();
			kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());

			kernel.AddComponent("common:key1=true", typeof(ICommon), typeof(CommonImpl1));
			kernel.AddComponent("common:secure=true", typeof(ICommon), typeof(CommonImpl2));

			GraphNode[] nodes = kernel.GraphNodes;
			Assert.IsNotNull(nodes);
			Assert.AreEqual(2, nodes.Length);
		}
开发者ID:Huddle,项目名称:Castle.Windsor,代码行数:12,代码来源:NamingPartsSubSystemTestCase.cs

示例4: GetAssignableHandlers

		public void GetAssignableHandlers()
		{
			IKernel kernel = new DefaultKernel();
			kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());

			kernel.AddComponent("common:key1=true", typeof(ICommon), typeof(CommonImpl1));
			kernel.AddComponent("common:secure=true", typeof(ICommon), typeof(CommonImpl2));

			IHandler[] handlers = kernel.GetAssignableHandlers(typeof(ICommon));

			Assert.IsNotNull(handlers);
			Assert.AreEqual(2, handlers.Length);
		}
开发者ID:Huddle,项目名称:Castle.Windsor,代码行数:13,代码来源:NamingPartsSubSystemTestCase.cs

示例5: ServiceLookup

		public void ServiceLookup()
		{
			IKernel kernel = new DefaultKernel();
			kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());

			kernel.AddComponent("common:key1=true", typeof(ICommon), typeof(CommonImpl1));
			kernel.AddComponent("common:secure=true", typeof(ICommon), typeof(CommonImpl2));

			ICommon common = kernel[typeof(ICommon)] as ICommon;

			Assert.IsNotNull(common);
			Assert.AreEqual(typeof(CommonImpl1), common.GetType());
		}
开发者ID:Huddle,项目名称:Castle.Windsor,代码行数:13,代码来源:NamingPartsSubSystemTestCase.cs

示例6: EmptyDelegateReturnsFirstTypeLoaded

		public void EmptyDelegateReturnsFirstTypeLoaded()
		{
			IKernel kernel = new DefaultKernel();
			kernel.AddSubSystem(SubSystemConstants.NamingKey, new KeySearchNamingSubSystem());

			kernel.AddComponent("1.common", typeof(ICommon), typeof(CommonImpl1));
			kernel.AddComponent("2.common", typeof(ICommon), typeof(CommonImpl2));

			ICommon common = kernel[typeof(ICommon)] as ICommon;

			Assert.IsNotNull(common);
			Assert.AreEqual(typeof(CommonImpl1), common.GetType());
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:13,代码来源:KeySearchNamingSubSystemTestCase.cs

示例7: ReturnsFirstMatchingType

		public void ReturnsFirstMatchingType()
		{
			IKernel kernel = new DefaultKernel();
			kernel.AddSubSystem(SubSystemConstants.NamingKey,
			                    new KeySearchNamingSubSystem(delegate(string key) { return key.StartsWith("1"); }));

			kernel.AddComponent("1.common", typeof(ICommon), typeof(CommonImpl1));
			kernel.AddComponent("11.common", typeof(ICommon), typeof(CommonImpl2));

			ICommon common = kernel[typeof(ICommon)] as ICommon;

			Assert.IsNotNull(common);
			Assert.AreEqual(typeof(CommonImpl1), common.GetType());
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:14,代码来源:KeySearchNamingSubSystemTestCase.cs

示例8: ReturnsCorrectType

		public void ReturnsCorrectType()
		{
			IKernel kernel = new DefaultKernel();
			kernel.AddSubSystem(SubSystemConstants.NamingKey,
			                    new KeySearchNamingSubSystem(
			                    	delegate(string key) { return key.StartsWith("castlestronghold.com"); }));

			kernel.AddComponent("castleproject.org.common", typeof(ICommon), typeof(CommonImpl1));
			kernel.AddComponent("castlestronghold.com.common", typeof(ICommon), typeof(CommonImpl2));

			ICommon common = kernel[typeof(ICommon)] as ICommon;

			Assert.IsNotNull(common);
			Assert.AreEqual(typeof(CommonImpl2), common.GetType());
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:15,代码来源:KeySearchNamingSubSystemTestCase.cs

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

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

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

示例12: Should_not_fail_when_constructor_parameter_and_public_property_with_private_setter_have_same_name

		public void Should_not_fail_when_constructor_parameter_and_public_property_with_private_setter_have_same_name()
		{
			IKernel kernel = new DefaultKernel();

			kernel.AddComponent<Service2>();
			kernel.AddComponent<Service1>();

			try
			{
				Service2 svc = kernel.Resolve<Service2>();
				Assert.IsNotNull(svc);
			}
			catch (NullReferenceException)
			{
				Assert.Fail("Should not have thrown a NullReferenceException");
			}
		}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:17,代码来源:IoC-108.cs

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

示例14: Public_property_with_Protected_setter_causes_Object_Reference_exception

		public void Public_property_with_Protected_setter_causes_Object_Reference_exception()
		{
			IKernel kernel = new DefaultKernel();

			kernel.AddComponent<Presenter>();
			kernel.AddComponent<View>();

			try
			{
				Presenter p = (Presenter)kernel.Resolve(typeof(Presenter));
				Assert.IsNotNull(p);
			}
			catch (NullReferenceException)
			{
				Assert.Fail("Should not have thrown a NullReferenceException");
			}
		}
开发者ID:ralescano,项目名称:castle,代码行数:17,代码来源:IoC-117.cs

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