本文整理汇总了C#中ServiceContainer.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer.Clear方法的具体用法?C# ServiceContainer.Clear怎么用?C# ServiceContainer.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceContainer
的用法示例。
在下文中一共展示了ServiceContainer.Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ShouldThrowIfDisposed
public void ShouldThrowIfDisposed()
{
var ioc = new ServiceContainer();
ioc.Dispose();
ioc.Clear();
}
示例3: ShouldNotBeDisposedOnClear
public void ShouldNotBeDisposedOnClear()
{
var ioc = new ServiceContainer();
ioc.Register(typeof(IService1), null, new DisposableService()); // DisposalPolicy = Manual
var disposableService = ioc.GetInstance<IService1>() as DisposableService;
Assert.IsNotNull(disposableService);
Assert.IsFalse(disposableService.Disposed);
ioc.Clear();
Assert.IsFalse(disposableService.Disposed);
ioc.Register(typeof(IService1), null, typeof(DisposableService), CreationPolicy.NonShared, DisposalPolicy.Manual);
disposableService = ioc.GetInstance<IService1>() as DisposableService;
Assert.IsNotNull(disposableService);
Assert.IsFalse(disposableService.Disposed);
ioc.Clear();
Assert.IsFalse(disposableService.Disposed);
}
示例4: ShouldBeDisposedOnClear
public void ShouldBeDisposedOnClear()
{
var ioc = new ServiceContainer();
// Shared service.
ioc.Register(typeof(IService1), null, typeof(DisposableService), CreationPolicy.Shared, DisposalPolicy.Automatic);
var disposableService = ioc.GetInstance<IService1>() as DisposableService;
Assert.IsNotNull(disposableService);
Assert.IsFalse(disposableService.Disposed);
ioc.Clear();
Assert.IsTrue(disposableService.Disposed);
Assert.IsNull(ioc.GetInstance<IService1>());
// Single non-shared service.
ioc.Register(typeof(IService1), null, typeof(DisposableService), CreationPolicy.NonShared, DisposalPolicy.Automatic);
disposableService = ioc.GetInstance<IService1>() as DisposableService;
Assert.IsNotNull(disposableService);
Assert.IsFalse(disposableService.Disposed);
ioc.Clear();
Assert.IsTrue(disposableService.Disposed);
Assert.IsNull(ioc.GetInstance<IService1>());
// Multiple non-shared service.
ioc.Register(typeof(IService1), null, typeof(DisposableService), CreationPolicy.NonShared, DisposalPolicy.Automatic);
var disposableService0 = ioc.GetInstance<IService1>() as DisposableService;
var disposableService1 = ioc.GetInstance<IService1>() as DisposableService;
var disposableService2 = ioc.GetInstance<IService1>() as DisposableService;
Assert.IsNotNull(disposableService0);
Assert.IsNotNull(disposableService1);
Assert.IsNotNull(disposableService2);
Assert.AreNotSame(disposableService0, disposableService1);
Assert.AreNotSame(disposableService0, disposableService2);
Assert.IsFalse(disposableService0.Disposed);
Assert.IsFalse(disposableService1.Disposed);
Assert.IsFalse(disposableService2.Disposed);
ioc.Clear();
Assert.IsTrue(disposableService0.Disposed);
Assert.IsNull(ioc.GetInstance<IService1>());
}