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


C# DefaultKernel.AddSubSystem方法代码示例

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


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

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

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

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

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

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

示例6: ReturnsFirstTypeWhenNotFound

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

			kernel.Register(Component.For(typeof(ICommon)).ImplementedBy(typeof(CommonImpl1)).Named("1.common"));
			kernel.Register(Component.For(typeof(ICommon)).ImplementedBy(typeof(CommonImpl2)).Named("2.common"));

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

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

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

示例8: MultiThreaded_RemoveResolve_Throws_When_LargeRatio_Of_ComponentsToService

		public void MultiThreaded_RemoveResolve_Throws_When_LargeRatio_Of_ComponentsToService()
		{
			var threadCount = 1000;
			var list = new List<Exception>();
			var locker = new object();
			var rand = new Random();
			var waitEvent = new ManualResetEvent(false);

			IKernel kernel = new DefaultKernel();
			kernel.AddSubSystem(SubSystemConstants.NamingKey, new KeySearchNamingSubSystem(delegate { return false; }));

			kernel.Register(Component.For(typeof(ICommon)).ImplementedBy(typeof(CommonImpl1)).Named("common"));

			WaitCallback resolveThread = delegate
			{
				waitEvent.WaitOne();
				while (threadCount > 0 && list.Count == 0)
				{
					try
					{
						kernel.Resolve<ICommon>();
					}
					catch (Exception e)
					{
						lock (locker)
						{
							list.Add(e);
						}
					}
				}
			};
			ThreadPool.QueueUserWorkItem(resolveThread);

			WaitCallback removeThread = delegate
			{
				waitEvent.WaitOne();
				kernel.RemoveComponent(threadCount + ".common");
				Interlocked.Decrement(ref threadCount);
			};
			for (var i = 0; i < threadCount; i++)
			{
				kernel.Register(Component.For(typeof(ICommon)).ImplementedBy(typeof(CommonImpl1)).Named(i + ".common"));
				ThreadPool.QueueUserWorkItem(removeThread);
			}

			waitEvent.Set();
			while (threadCount > 0 && list.Count == 0)
			{
				Thread.Sleep(15);
			}

			if (list.Count > 0)
			{
				throw list[0];
			}
		}
开发者ID:vbedegi,项目名称:Castle.InversionOfControl,代码行数:56,代码来源:KeySearchNamingSubSystemTestCase.cs

示例9: ComponentUnregistersProperly

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

			kernel.AddSubSystem(SubSystemConstants.NamingKey,
			                    new KeySearchNamingSubSystem(delegate(string key) { return key.StartsWith("2"); }));

			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(CommonImpl2), common.GetType());

			kernel.RemoveComponent("2.common");

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

			Assert.IsNotNull(common);
			Assert.AreEqual(typeof(CommonImpl1), common.GetType());

			kernel.RemoveComponent("1.common");
			Assert.AreEqual(0, kernel.GetHandlers(typeof(ICommon)).Length);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:25,代码来源:KeySearchNamingSubSystemTestCase.cs

示例10: MultiThreaded_RemoveResolve_Throws_When_LargeRatio_Of_ComponentsToService

		public void MultiThreaded_RemoveResolve_Throws_When_LargeRatio_Of_ComponentsToService()
		{
			int threadCount = 1000;
			ArrayList list = ArrayList.Synchronized(new ArrayList());
			Random rand = new Random();
			ManualResetEvent waitEvent = new ManualResetEvent(false);

			IKernel kernel = new DefaultKernel();
			kernel.AddSubSystem(SubSystemConstants.NamingKey, new KeySearchNamingSubSystem(delegate { return false; }));

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

			WaitCallback resolveThread = delegate
			                             	{
			                             		waitEvent.WaitOne();
			                             		while(threadCount > 0 && list.Count == 0)
			                             		{
			                             			try
			                             			{
			                             				ICommon common = kernel[typeof(ICommon)] as ICommon;
			                             			}
			                             			catch(Exception e)
			                             			{
			                             				list.Add(e);
			                             			}
			                             		}
			                             	};
			ThreadPool.QueueUserWorkItem(resolveThread);

			WaitCallback removeThread = delegate
			                            	{
			                            		waitEvent.WaitOne();
			                            		kernel.RemoveComponent(threadCount + ".common");
			                            		Interlocked.Decrement(ref threadCount);
			                            	};
			for(int i = 0; i < threadCount; i++)
			{
				kernel.AddComponent(i + ".common", typeof(ICommon), typeof(CommonImpl1));
				ThreadPool.QueueUserWorkItem(removeThread);
			}

			waitEvent.Set();
			while(threadCount > 0 && list.Count == 0)
			{
				Thread.Sleep(15);
			}

			if (list.Count > 0)
			{
				throw (Exception) list[0];
			}
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:52,代码来源:KeySearchNamingSubSystemTestCase.cs

示例11: MultiThreadedAddResolve

		public void MultiThreadedAddResolve()
		{
			int threadCount = 100;
			ArrayList list = ArrayList.Synchronized(new ArrayList());
			Random rand = new Random();
			ManualResetEvent waitEvent = new ManualResetEvent(false);

			IKernel kernel = new DefaultKernel();
			kernel.AddSubSystem(SubSystemConstants.NamingKey, new KeySearchNamingSubSystem());
			kernel.AddComponent("common", typeof(ICommon), typeof(CommonImpl1));

			WaitCallback resolveThread = delegate
			                             	{
			                             		waitEvent.WaitOne();
			                             		while(threadCount > 0 && list.Count == 0)
			                             		{
			                             			try
			                             			{
			                             				ICommon common = kernel[typeof(ICommon)] as ICommon;
			                             			}
			                             			catch(Exception e)
			                             			{
			                             				list.Add(e.ToString());
			                             			}
			                             		}
			                             	};
			ThreadPool.QueueUserWorkItem(resolveThread);

			WaitCallback addThread = delegate
			                         	{
			                         		waitEvent.WaitOne();
			                         		kernel.AddComponent(rand.Next() + ".common", typeof(ICommon), typeof(CommonImpl1));
			                         		Interlocked.Decrement(ref threadCount);
			                         	};
			for(int i = 0; i < threadCount; i++)
			{
				ThreadPool.QueueUserWorkItem(addThread);
			}

			waitEvent.Set();
			while(threadCount > 0 && list.Count == 0)
			{
				Thread.Sleep(15);
			}

			if (list.Count > 0)
			{
				Assert.Fail(list[0].ToString());
			}
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:50,代码来源:KeySearchNamingSubSystemTestCase.cs

示例12: SetUpTests

		public void SetUpTests()
		{
			kernel = new DefaultKernel();
			kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());
		}
开发者ID:vbedegi,项目名称:Castle.InversionOfControl,代码行数:5,代码来源:NamingPartsSubSystemTestCase.cs

示例13: MultiThreadedAddResolve

		public void MultiThreadedAddResolve([Values(100)] int threadCount)
		{
			object locker = new object();
			IList<string> list = new List<string>();
			ManualResetEvent waitEvent = new ManualResetEvent(false);

			IKernel kernel = new DefaultKernel();
			kernel.AddSubSystem(SubSystemConstants.NamingKey, new KeySearchNamingSubSystem());
			kernel.AddComponent("common", typeof(ICommon), typeof(CommonImpl1));

			WaitCallback resolveThread = delegate
			                             	{
			                             		waitEvent.WaitOne();
			                             		while(threadCount > 0 && list.Count == 0)
			                             		{
			                             			try
			                             			{
			                             				ICommon common = kernel[typeof(ICommon)] as ICommon;
			                             			}
			                             			catch(Exception e)
			                             			{
														lock (locker)
														{
															list.Add(e.ToString());
														}
			                             			}
			                             		}
			                             	};
			ThreadPool.QueueUserWorkItem(resolveThread);

			WaitCallback addThread = delegate
			                         	{
			                         		waitEvent.WaitOne();
			                         		kernel.AddComponent(Guid.NewGuid() + ".common", typeof(ICommon), typeof(CommonImpl1));
			                         		Interlocked.Decrement(ref threadCount);
			                         	};
			for(int i = 0; i < threadCount; i++)
			{
				ThreadPool.QueueUserWorkItem(addThread);
			}

			waitEvent.Set();
			while(threadCount > 0 && list.Count == 0)
			{
				Thread.Sleep(15);
			}

			if (list.Count > 0)
			{
				Assert.Fail(list[0].ToString());
			}
		}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:52,代码来源:KeySearchNamingSubSystemTestCase.cs

示例14: SingleComponentUnregistersProperly

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

			kernel.Register(Component.For(typeof(ICommon)).ImplementedBy(typeof(CommonImpl1)).Named("1.common"));

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

			Assert.IsNotNull(common);
			Assert.AreEqual(typeof(CommonImpl1), common.GetType());

			kernel.RemoveComponent("1.common");

			Assert.IsFalse(kernel.HasComponent("1.common"));
			Assert.IsFalse(kernel.HasComponent(typeof(CommonImpl1)));
			common = kernel[typeof(ICommon)] as ICommon;
		}
开发者ID:gschuager,项目名称:Castle.Windsor,代码行数:19,代码来源:KeySearchNamingSubSystemTestCase.cs


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