本文整理汇总了C#中Castle.MicroKernel.DefaultKernel.AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultKernel.AddComponent方法的具体用法?C# DefaultKernel.AddComponent怎么用?C# DefaultKernel.AddComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Castle.MicroKernel.DefaultKernel
的用法示例。
在下文中一共展示了DefaultKernel.AddComponent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Kernel_should_select_ctor_with_available_dependencies
public void Kernel_should_select_ctor_with_available_dependencies()
{
var kernel = new DefaultKernel();
kernel.AddComponent<Service>();
kernel.AddComponent<ComponentX>();
kernel.AddComponent<ComponentY>();
var service = kernel.Resolve<Service>();
Assert.IsNull(service.A);
Assert.IsNotNull(service.X);
Assert.IsNotNull(service.Y);
}
示例2: 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.AddComponent("b", typeof(NoInterfaceStartableComponent));
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);
}
示例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"];
}
示例4: LoadWindsorAssembly
public void LoadWindsorAssembly()
{
IKernel kernel = new DefaultKernel();
kernel.AddComponent( "A", typeof(AssemblyResolverComponent) );
AssemblyResolverComponent comp = (AssemblyResolverComponent) kernel["A"];
comp.Start();
Type windsor = Type.GetType(
"Castle.Windsor.WindsorContainer, Castle.Windsor", false, false );
Assert.IsNotNull(windsor);
}
示例5: TestInterfaceBasedStartable
public void TestInterfaceBasedStartable()
{
IKernel kernel = new DefaultKernel();
kernel.ComponentCreated += new ComponentInstanceDelegate(OnStartableComponentStarted);
kernel.AddFacility("startable", new StartableFacility());
kernel.AddComponent("a", typeof(StartableComponent));
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);
}
示例6: SimpleRegistration
private static void SimpleRegistration()
{
IKernel kernel = new DefaultKernel();
//kernel.Resolver.AddSubResolver(new ArrayResolver(kernel));
//kernel.Resolver.AddSubResolver(new ListResolver(kernel));
kernel.AddComponent("foo", typeof(IFoo), typeof(Foo));
IFoo foo = kernel[typeof(IFoo)] as IFoo;
if (foo != null)
{
foo.SayHello();
}
IFoo foo2 = kernel["foo"] as IFoo;
if (foo2 != null)
{
foo2.SayHello();
}
}
示例7: 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);
}
示例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.AddComponent("chainparent", typeof(StartableChainParent));
Assert.AreEqual(0, StartableChainDependency.startcount);
Assert.AreEqual(0, StartableChainDependency.createcount);
// Add generic dependency. This is not startable so won't get created.
kernel.AddComponent("chaingeneric", typeof(StartableChainGeneric<>));
Assert.AreEqual(0, StartableChainDependency.startcount);
Assert.AreEqual(0, StartableChainDependency.createcount);
// Add dependency. This will satisfy the dependency so everything will start.
kernel.AddComponent("chaindependency", typeof(StartableChainDependency));
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);
}