本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}