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


C# Container.For方法代码示例

本文整理汇总了C#中Container.For方法的典型用法代码示例。如果您正苦于以下问题:C# Container.For方法的具体用法?C# Container.For怎么用?C# Container.For使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Container的用法示例。


在下文中一共展示了Container.For方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_return_an_instance_with_method_chaining_syntax

        public void Should_return_an_instance_with_method_chaining_syntax()
        {
            var container = new Container();
            container.For<ICounter>().Use<Counter>();
            container.For<IRepository>().Use<Repository>();
            container.For<Processor>().Use<Processor>();

            var processor = container.Resolve<Processor>();

            Assert.IsInstanceOf<Processor>(processor);
            Assert.IsInstanceOf<Counter>(processor.Counter);
            Assert.IsInstanceOf<Repository>(processor.Repository);
        }
开发者ID:jason-d,项目名称:IoCContainer,代码行数:13,代码来源:ContainerTests.cs

示例2: Get_WhenInstanceHasDependency_ReturnsCorrectInstance

        public void Get_WhenInstanceHasDependency_ReturnsCorrectInstance()
        {
            // Arrange
            var c = new Container();
            c.For<IVehicle>().Use<Car>();
            c.For<IEngine>().Use<DieselEngine>();

            // Act
            var vehicle = c.Get<IVehicle>();

            // Assert
            Assert.IsInstanceOf<Car>(vehicle);
            Assert.IsInstanceOf<DieselEngine>(((Car)vehicle).Engine);
        }
开发者ID:3komma14,项目名称:SimpleIOC,代码行数:14,代码来源:ContainerTests.cs

示例3: Get_WhenInstanceHasMultipleCtors_Throws

        public void Get_WhenInstanceHasMultipleCtors_Throws()
        {
            // Arrange
            var c = new Container();

            // Act
            // Assert
            Assert.Throws<InvalidOperationException>(() => c.For<IVehicle>().Use<Train>());
        }
开发者ID:3komma14,项目名称:SimpleIOC,代码行数:9,代码来源:ContainerTests.cs

示例4: Get_WhenInstanceDependencyNotConfigures_Throws

        public void Get_WhenInstanceDependencyNotConfigures_Throws()
        {
            // Arrange
            var c = new Container();
            c.For<IVehicle>().Use<Car>();

            // Act
            // Assert
            Assert.Throws<InvalidOperationException>(() => c.Get<IVehicle>());
        }
开发者ID:3komma14,项目名称:SimpleIOC,代码行数:10,代码来源:ContainerTests.cs

示例5: Get_WhenInstanceCtorHasNonConfiguresValueType_ReturnsCorrectInstance

        public void Get_WhenInstanceCtorHasNonConfiguresValueType_ReturnsCorrectInstance()
        {
            // Arrange
            var c = new Container();
            c.For<IVehicle>().Use<Bicycle>();

            // Act
            var vehicle = c.Get<IVehicle>();

            // Assert
            Assert.IsInstanceOf<Bicycle>(vehicle);
            Assert.AreEqual(0, ((Bicycle)vehicle).NumberOfGears);
        }
开发者ID:3komma14,项目名称:SimpleIOC,代码行数:13,代码来源:ContainerTests.cs

示例6: Get_WhenInstanceIsClassWithDependency_ReturnsClass

        public void Get_WhenInstanceIsClassWithDependency_ReturnsClass()
        {
            // Arrange
            var c = new Container();
            c.For<IEngine>().Use<DieselEngine>();

            // Act
            var vehicle = c.Get<Car>();

            // Assert
            Assert.IsNotNull(vehicle);
            Assert.IsNotNull(vehicle.Engine);
        }
开发者ID:3komma14,项目名称:SimpleIOC,代码行数:13,代码来源:ContainerTests.cs

示例7: Get_WhenInstanceIsExplicitSetAndResolvedSeveralTimes_ReturnsSameInstance

        public void Get_WhenInstanceIsExplicitSetAndResolvedSeveralTimes_ReturnsSameInstance()
        {
            // Arrange
            var mc = new Motorcycle();
            var c = new Container();
            c.For<IVehicle>().Use(mc);

            // Act
            var vehicle1 = c.Get<IVehicle>();
            var vehicle2 = c.Get<IVehicle>();

            // Assert
            Assert.IsNotNull(vehicle1);
            Assert.IsNotNull(vehicle2);
            Assert.AreSame(vehicle1, vehicle2);
        }
开发者ID:3komma14,项目名称:SimpleIOC,代码行数:16,代码来源:ContainerTests.cs

示例8: Get_WhenInstanceIsConfigured_ReturnsCorrectInstance

        public void Get_WhenInstanceIsConfigured_ReturnsCorrectInstance()
        {
            // Arrange
            var c = new Container();
            c.For<IVehicle>().Use<Motorcycle>();

            // Act
            var vehicle = c.Get<IVehicle>();

            // Assert
            Assert.IsInstanceOf<Motorcycle>(vehicle);
        }
开发者ID:3komma14,项目名称:SimpleIOC,代码行数:12,代码来源:ContainerTests.cs

示例9: Get_WhenInstanceIsConfiguredWithLamdas_ReturnsCorrectInstance

        public void Get_WhenInstanceIsConfiguredWithLamdas_ReturnsCorrectInstance()
        {
            // Arrange
            var c = new Container();
            c.For<IVehicle>().Use<Bicycle>(() => new Bicycle(10));

            // Act
            var vehicle = c.Get<IVehicle>();

            // Assert
            Assert.IsInstanceOf<Bicycle>(vehicle);
            Assert.AreEqual(10, ((Bicycle)vehicle).NumberOfGears);
        }
开发者ID:3komma14,项目名称:SimpleIOC,代码行数:13,代码来源:ContainerTests.cs

示例10: Should_return_the_same_object_if_a_singleton_with_method_chaining_syntax

        public void Should_return_the_same_object_if_a_singleton_with_method_chaining_syntax()
        {
            var container = new Container();
            container.For<ICounter>().Use<Counter>().AsSingleton();

            var counterA = container.Resolve<Counter>();
            var counterB = container.Resolve<Counter>();

            Assert.AreSame(counterA, counterB);
        }
开发者ID:jason-d,项目名称:IoCContainer,代码行数:10,代码来源:ContainerTests.cs


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