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


C# DefaultKernel.RemoveComponent方法代码示例

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


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

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

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

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

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