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


C# DefaultKernel.AddFacility方法代码示例

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


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

示例1: TestComponentWithNoInterface

		public void TestComponentWithNoInterface()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentCreated += new ComponentInstanceDelegate(OnNoInterfaceStartableComponentStarted);

			MutableConfiguration compNode = new MutableConfiguration("component");
			compNode.Attributes["id"] = "b";
			compNode.Attributes["startable"] = "true";
			compNode.Attributes["startMethod"] = "Start";
			compNode.Attributes["stopMethod"] = "Stop";

			kernel.ConfigurationStore.AddComponentConfiguration("b", compNode);

			kernel.AddFacility("startable", new StartableFacility());
			kernel.Register(Component.For(typeof(NoInterfaceStartableComponent)).Named("b"));

			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			NoInterfaceStartableComponent component = kernel["b"] as NoInterfaceStartableComponent;

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
开发者ID:gschuager,项目名称:Castle.Windsor,代码行数:27,代码来源:StartableFacilityTestCase.cs

示例2: Starts_component_without_start_method

		public void Starts_component_without_start_method()
		{
			ClassWithInstanceCount.InstancesCount = 0;
			IKernel kernel = new DefaultKernel();
			kernel.AddFacility<StartableFacility>(f => f.DeferredTryStart());
			kernel.Register(Component.For<ClassWithInstanceCount>().Start());
			Assert.AreEqual(1, ClassWithInstanceCount.InstancesCount);
		}
开发者ID:HEskandari,项目名称:Castle.InversionOfControl,代码行数:8,代码来源:StartableFacilityTestCase.cs

示例3: Main

		public static void Main(string[] args)
		{
			IKernel kernel = new DefaultKernel();
			
			kernel.AddFacility("non.opt.props", new NonOptionalPropertiesFacility());
			
			kernel.AddComponent("sql.connmng", typeof(SqlConnectionManager));
			
			SqlConnectionManager connManager = (SqlConnectionManager) kernel["sql.connmng"];
		}
开发者ID:ralescano,项目名称:castle,代码行数:10,代码来源:App.cs

示例4: FacilityConfig_is_not_null

		public void FacilityConfig_is_not_null()
		{
			using (var c = new DefaultKernel())
			{
				const string facilityKey = "hiper";
				var config = new MutableConfiguration("facility");
				c.ConfigurationStore.AddFacilityConfiguration(facilityKey, config);
				var facility = new HiperFacility();
				c.AddFacility(facilityKey, facility);
				Assert.IsTrue(facility.Initialized);
			}
		}
开发者ID:RookieX,项目名称:Windsor,代码行数:12,代码来源:IoC-334.cs

示例5: SetUp

		public void SetUp()
		{
			kernel = new DefaultKernel();

			kernel.AddFacility<StartableFacility>();

			kernel.Register(
				Component.For<StartableDisposableAndInitializableComponent>()
					.LifeStyle.Transient
				);

			component = kernel.Resolve<StartableDisposableAndInitializableComponent>();
			component.DoSomething();
			kernel.ReleaseComponent(component);

			calledMethods = component.calledMethods;
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:17,代码来源:IoC_113.cs

示例6: TestInterfaceBasedStartable

		public void TestInterfaceBasedStartable()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentCreated += new ComponentInstanceDelegate(OnStartableComponentStarted);

			kernel.AddFacility("startable", new StartableFacility());

			kernel.Register(Component.For(typeof(StartableComponent)).Named("a"));

			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			StartableComponent component = kernel["a"] as StartableComponent;

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
开发者ID:gschuager,项目名称:Castle.Windsor,代码行数:20,代码来源:StartableFacilityTestCase.cs

示例7: TestStartableWithRegisteredCustomDependencies

		public void TestStartableWithRegisteredCustomDependencies()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentCreated += new ComponentInstanceDelegate(OnStartableComponentStarted);

			kernel.AddFacility("startable", new StartableFacility());

			var dependencies = new Dictionary<string, object> { { "config", 1 } };
			kernel.Register(Component.For(typeof(StartableComponentCustomDependencies)).Named("a"));
			kernel.RegisterCustomDependencies(typeof(StartableComponentCustomDependencies), dependencies);

			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			StartableComponentCustomDependencies component = kernel["a"] as StartableComponentCustomDependencies;

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
开发者ID:gschuager,项目名称:Castle.Windsor,代码行数:22,代码来源:StartableFacilityTestCase.cs

示例8: TestStartableChainWithGenerics

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

			kernel.AddFacility("startable", new StartableFacility());

			// Add parent. This has a dependency so won't be started yet.
			kernel.Register(Component.For(typeof(StartableChainParent)).Named("chainparent"));

			Assert.AreEqual(0, StartableChainDependency.startcount);
			Assert.AreEqual(0, StartableChainDependency.createcount);

			// Add generic dependency. This is not startable so won't get created. 
			kernel.Register(Component.For(typeof(StartableChainGeneric<>)).Named("chaingeneric"));

			Assert.AreEqual(0, StartableChainDependency.startcount);
			Assert.AreEqual(0, StartableChainDependency.createcount);

			// Add dependency. This will satisfy the dependency so everything will start.
			kernel.Register(Component.For(typeof(StartableChainDependency)).Named("chaindependency"));

			Assert.AreEqual(1, StartableChainParent.startcount);
			Assert.AreEqual(1, StartableChainParent.createcount);
			Assert.AreEqual(1, StartableChainDependency.startcount);
			Assert.AreEqual(1, StartableChainDependency.createcount);
			Assert.AreEqual(1, StartableChainGeneric<string>.createcount);
		}
开发者ID:gschuager,项目名称:Castle.Windsor,代码行数:27,代码来源:StartableFacilityTestCase.cs

示例9: TestStartableCustomDependencies

		public void TestStartableCustomDependencies()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentCreated += new ComponentInstanceDelegate(OnStartableComponentStarted);

			kernel.AddFacility("startable", new StartableFacility());

			kernel.Register(
				Component.For<StartableComponentCustomDependencies>()
					.Named("a")
					.DependsOn(Property.ForKey("config").Eq(1))
				);
			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			StartableComponentCustomDependencies component = kernel["a"] as StartableComponentCustomDependencies;

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
开发者ID:gschuager,项目名称:Castle.Windsor,代码行数:23,代码来源:StartableFacilityTestCase.cs

示例10: TestStartableWithRegisteredCustomDependencies

		public void TestStartableWithRegisteredCustomDependencies()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentCreated += new ComponentInstanceDelegate(OnStartableComponentStarted);

			kernel.AddFacility("startable", new StartableFacility());

			Hashtable dependencies = new Hashtable();
			dependencies.Add("config", 1);
			kernel.AddComponent("a", typeof(StartableComponentCustomDependencies));
			kernel.RegisterCustomDependencies(typeof(StartableComponentCustomDependencies), dependencies);

			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			StartableComponentCustomDependencies component = kernel["a"] as StartableComponentCustomDependencies;

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
开发者ID:ralescano,项目名称:castle,代码行数:23,代码来源:StartableFacilityTestCase.cs

示例11: TestStartableComponentWithServiceDependency

		public void TestStartableComponentWithServiceDependency()
		{
			IKernel kernel = new DefaultKernel();
			kernel.ComponentModelBuilder.AddContributor(new ServiceDependencyComponentInspector());
			kernel.ComponentCreated += new ComponentInstanceDelegate(OnStartableComponentWithServiceDependencyStarted);

			kernel.AddFacility("startable", new StartableFacility());

			kernel.Register(Component.For<StartableComponentWithServiceDependency>());

			Assert.IsFalse(startableCreatedBeforeResolved, "Component was started before dependency was registered");

			kernel.Register(Component.For<ServiceDependency>());

			Assert.IsTrue(startableCreatedBeforeResolved, "Component was not properly started");

			StartableComponentWithServiceDependency component = kernel.Resolve<StartableComponentWithServiceDependency>();

			Assert.IsNotNull(component);
			Assert.IsTrue(component.Started);
			Assert.IsFalse(component.Stopped);

			kernel.ReleaseComponent(component);
			Assert.IsTrue(component.Stopped);
		}
开发者ID:mdavis,项目名称:Castle.InversionOfControl,代码行数:25,代码来源:StartableFacilityTestCase.cs

示例12: SetUp

		public void SetUp()
		{
			kernel = new DefaultKernel();
			kernel.AddFacility<FactorySupportFacility>();
		}
开发者ID:vbedegi,项目名称:Castle.InversionOfControl,代码行数:5,代码来源:FactorySupportFluentTestCase.cs


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