本文整理汇总了C#中DefaultKernel.HasComponent方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultKernel.HasComponent方法的具体用法?C# DefaultKernel.HasComponent怎么用?C# DefaultKernel.HasComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DefaultKernel
的用法示例。
在下文中一共展示了DefaultKernel.HasComponent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KernelSerialization
public void KernelSerialization()
{
IKernel kernel = new DefaultKernel();
kernel.Register(Component.For(typeof(CustomerImpl)).Named("key"));
Assert.IsTrue(kernel.HasComponent("key"));
MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, kernel);
stream.Position = 0;
IKernel desKernel = (IKernel) formatter.Deserialize(stream);
Assert.IsTrue(desKernel.HasComponent("key"));
}
示例2: SingleComponentUnregistersProperly
public void SingleComponentUnregistersProperly()
{
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));
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;
}
示例3: ChildKernelFindsAndCreateParentComponent
public void ChildKernelFindsAndCreateParentComponent()
{
IKernel subkernel = new DefaultKernel();
kernel.Register(Component.For(typeof(DefaultTemplateEngine)).Named("templateengine"));
kernel.AddChildKernel(subkernel);
Assert.IsTrue(subkernel.HasComponent(typeof(DefaultTemplateEngine)));
Assert.IsNotNull(subkernel.Resolve<DefaultTemplateEngine>());
}
示例4: ChildKernelFindsAndCreateParentComponent
public void ChildKernelFindsAndCreateParentComponent()
{
IKernel subkernel = new DefaultKernel();
kernel.AddComponent("templateengine", typeof(DefaultTemplateEngine));
kernel.AddChildKernel(subkernel);
Assert.IsTrue(subkernel.HasComponent(typeof(DefaultTemplateEngine)));
Assert.IsNotNull(subkernel[typeof(DefaultTemplateEngine)]);
}