本文整理汇总了C#中ServiceContainer.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer.Cast方法的具体用法?C# ServiceContainer.Cast怎么用?C# ServiceContainer.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceContainer
的用法示例。
在下文中一共展示了ServiceContainer.Cast方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClearContainer
public void ClearContainer()
{
var ioc = new ServiceContainer();
Assert.AreEqual(3, ioc.Cast<object>().Count()); // By default only ServiceContainer is registered in 3 variants.
ioc.Clear();
Assert.AreEqual(0, ioc.Cast<object>().Count());
ioc.Register(typeof(IService1), null, typeof(Service1));
Assert.AreEqual(1, ioc.Cast<object>().Count());
ioc.Clear();
Assert.AreEqual(0, ioc.Cast<object>().Count());
}
示例2: ShouldContainSelf
public void ShouldContainSelf()
{
var ioc = new ServiceContainer();
Assert.AreSame(ioc, ioc.Cast<object>().First());
}
示例3: ReplaceType
public void ReplaceType()
{
var ioc = new ServiceContainer();
ioc.Register(typeof(IService1), null, typeof(Service1));
var instance = ioc.GetInstance<IService1>();
Assert.IsNotNull(instance);
Assert.AreEqual(4, ioc.Cast<object>().Count());
ioc.Register(typeof(IService1), null, typeof(Service1));
var newInstance = ioc.GetInstance<IService1>();
Assert.IsNotNull(newInstance);
Assert.AreNotEqual(newInstance, instance);
Assert.AreEqual(4, ioc.Cast<object>().Count());
}
示例4: ReplaceInstance
public void ReplaceInstance()
{
var ioc = new ServiceContainer();
var instance = new Service1();
ioc.Register(typeof(IService1), null, instance);
Assert.AreEqual(instance, ioc.GetInstance<IService1>());
Assert.AreEqual(4, ioc.Cast<object>().Count());
instance = new Service1();
ioc.Register(typeof(IService1), null, instance);
Assert.AreEqual(instance, ioc.GetInstance<IService1>());
Assert.AreEqual(4, ioc.Cast<object>().Count());
}
示例5: RegisterNamedType
public void RegisterNamedType()
{
var ioc = new ServiceContainer();
ioc.Register(typeof(IService1), null, typeof(Service1));
ioc.Register(typeof(IService1), "NamedService1", typeof(Service1));
var instance = ioc.GetInstance<IService1>();
Assert.IsNotNull(instance);
Assert.AreEqual(instance, ioc.GetInstance<IService1>());
var namedInstance = ioc.GetInstance<IService1>("NamedService1");
Assert.IsNotNull(namedInstance);
Assert.AreEqual(namedInstance, ioc.GetInstance<IService1>("NamedService1"));
Assert.AreEqual(5, ioc.Cast<object>().Count());
}
示例6: DefaultIocContainerShouldBeEmpty
public void DefaultIocContainerShouldBeEmpty()
{
var ioc = new ServiceContainer();
Assert.AreEqual(3, ioc.Cast<object>().Count()); // By default only ServiceContainer is registered.
}
示例7: CreateChildContainer
public void CreateChildContainer()
{
var ioc = new ServiceContainer();
Assert.AreSame(ioc, ioc.Cast<object>().First());
var childContainer = ioc.CreateChildContainer();
Assert.AreSame(childContainer, childContainer.Cast<object>().First());
}