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


C# ServiceContainer.Cast方法代码示例

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

示例2: ShouldContainSelf

 public void ShouldContainSelf()
 {
     var ioc = new ServiceContainer();
       Assert.AreSame(ioc, ioc.Cast<object>().First());
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:5,代码来源:ServiceContainerTest.cs

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

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

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

示例6: DefaultIocContainerShouldBeEmpty

 public void DefaultIocContainerShouldBeEmpty()
 {
     var ioc = new ServiceContainer();
       Assert.AreEqual(3, ioc.Cast<object>().Count()); // By default only ServiceContainer is registered.
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:5,代码来源:ServiceContainerTest.cs

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


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