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


C# ServiceContainer.Clear方法代码示例

本文整理汇总了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());
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:14,代码来源:ServiceContainerTest.cs

示例2: ShouldThrowIfDisposed

 public void ShouldThrowIfDisposed()
 {
     var ioc = new ServiceContainer();
       ioc.Dispose();
       ioc.Clear();
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:6,代码来源:ServiceContainerTest.cs

示例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);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:22,代码来源:ServiceContainerTest.cs

示例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>());
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:45,代码来源:ServiceContainerTest.cs


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