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


C# Container.RegisterConstructorSelectorConvention方法代码示例

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


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

示例1: RegisterWithConstructor_WithValidArgument_Succeeds

        public void RegisterWithConstructor_WithValidArgument_Succeeds()
        {
            // Arrange
            var container = new Container();

            var convention = container.RegisterConstructorSelectorConvention();
            
            // Act
            convention.Register<ICommand, MultipleConstructorsCommand>(ConstructorSelector.MostParameters);
        }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:10,代码来源:ConstructorRegistrationExtensionsTests.cs

示例2: Register_RegisterConstructorSelectorConvention_CanNotRegisterTypeWithMultipleConstructors

        public void Register_RegisterConstructorSelectorConvention_CanNotRegisterTypeWithMultipleConstructors()
        {
            // Arrange
            var container = new Container();

            var convention = container.RegisterConstructorSelectorConvention();
            
            // Act
            Action action = () => container.Register<ICommand, MultipleConstructorsCommand>();

            // Assert
            AssertThat.Throws<ArgumentException>(action);
        }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:13,代码来源:ConstructorRegistrationExtensionsTests.cs

示例3: GetInstance_TypeRegisteredWithSpecificConstructor_CreatesThatTypeUsingThatConstructor1

        public void GetInstance_TypeRegisteredWithSpecificConstructor_CreatesThatTypeUsingThatConstructor1()
        {
            // Arrange
            var container = new Container();

            var convention = container.RegisterConstructorSelectorConvention();

            convention.Register<ICommand, MultipleConstructorsCommand>(ConstructorSelector.LeastParameters);

            // Act
            var command = (MultipleConstructorsCommand)container.GetInstance<ICommand>();

            // Assert
            Assert.AreEqual(MultipleConstructorsCommand.LeastParametersConstructor, command.ConstructorType);
        }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:15,代码来源:ConstructorRegistrationExtensionsTests.cs

示例4: GetInstance_TypeRegisteredWithSpecificConstructor_CreatesThatTypeUsingThatConstructor2

        public void GetInstance_TypeRegisteredWithSpecificConstructor_CreatesThatTypeUsingThatConstructor2()
        {
            // Arrange
            var container = new Container();

            var convention = container.RegisterConstructorSelectorConvention();

            container.Register<ILogger, NullLogger>(Lifestyle.Singleton);
            container.Register<ISomeDependency, SomeDependency>(Lifestyle.Singleton);

            convention.Register<ICommand, MultipleConstructorsCommand>(ConstructorSelector.MostParameters);

            // Act
            var command = (MultipleConstructorsCommand)container.GetInstance<ICommand>();

            // Assert
            Assert.AreEqual(MultipleConstructorsCommand.MostParametersConstructor, command.ConstructorType);
        }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:18,代码来源:ConstructorRegistrationExtensionsTests.cs

示例5: GetInstance_ConcreteTypeRegisteredWithTwoDifferentKeys_ResolvesThatTypeWithTheDifferentConstructors

        public void GetInstance_ConcreteTypeRegisteredWithTwoDifferentKeys_ResolvesThatTypeWithTheDifferentConstructors()
        {
            // Arrange
            var container = new Container();

            var convention = container.RegisterConstructorSelectorConvention();

            container.Register<ILogger, NullLogger>(Lifestyle.Singleton);
            container.Register<ISomeDependency, SomeDependency>(Lifestyle.Singleton);

            convention.Register<ICommand, MultipleConstructorsCommand>(ConstructorSelector.MostParameters);
            convention.Register<MultipleConstructorsCommand>(ConstructorSelector.LeastParameters);

            // Act
            var command1 = (MultipleConstructorsCommand)container.GetInstance<ICommand>();
            var command2 = container.GetInstance<MultipleConstructorsCommand>();

            // Assert
            Assert.AreEqual(MultipleConstructorsCommand.MostParametersConstructor, command1.ConstructorType);
            Assert.AreEqual(MultipleConstructorsCommand.LeastParametersConstructor, command2.ConstructorType);
        }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:21,代码来源:ConstructorRegistrationExtensionsTests.cs


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