本文整理汇总了C#中Container.AllowResolvingParameterizedFuncFactories方法的典型用法代码示例。如果您正苦于以下问题:C# Container.AllowResolvingParameterizedFuncFactories方法的具体用法?C# Container.AllowResolvingParameterizedFuncFactories怎么用?C# Container.AllowResolvingParameterizedFuncFactories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container.AllowResolvingParameterizedFuncFactories方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AllowResolvingParameterizedFuncFactories_WithParametersInIncorrectOrder_ThrowExpectedException
public void AllowResolvingParameterizedFuncFactories_WithParametersInIncorrectOrder_ThrowExpectedException()
{
// Arrange
var container = new Container();
container.AllowResolvingParameterizedFuncFactories();
container.Register<ILogger, NullLogger>(Lifestyle.Singleton);
container.Register<ICommand, ConcreteCommand>();
// Act
Action action = () => container.GetInstance<Func<int, string, Tuple<ILogger, string, int>>>();
// Assert
AssertThat.Throws<ActivationException>(action);
}
示例2: AllowResolvingParameterizedFuncFactories_WithDependencies_PrevervesLifestyles
public void AllowResolvingParameterizedFuncFactories_WithDependencies_PrevervesLifestyles()
{
// Arrange
var container = new Container();
container.AllowResolvingParameterizedFuncFactories();
container.Register<ILogger, NullLogger>(Lifestyle.Singleton);
container.Register<ICommand, ConcreteCommand>();
// Act
var tupleFactory = container.GetInstance<Func<string, Tuple<ILogger, string, ICommand>>>();
var tuple1 = tupleFactory(null);
var tuple2 = tupleFactory(null);
// Assert
Assert.AreSame(tuple1.Item1, tuple2.Item1, "Logger is expected to be singleton");
Assert.AreNotSame(tuple1.Item3, tuple2.Item3, "Command is expected to be transient");
}
示例3: AllowResolvingParameterizedFuncFactories_ResolvingTypeWithOneDependencyAsLastCtorParameter_Succeeds
public void AllowResolvingParameterizedFuncFactories_ResolvingTypeWithOneDependencyAsLastCtorParameter_Succeeds()
{
// Arrange
var container = new Container();
container.AllowResolvingParameterizedFuncFactories();
container.Register<ILogger, NullLogger>();
// Act
var tupleFactory = container.GetInstance<Func<int, string, Tuple<int, string, ILogger>>>();
var tuple = tupleFactory(0, null);
// Assert
AssertThat.IsInstanceOfType(typeof(ILogger), tuple.Item3);
}
示例4: Container
public void AllowResolvingParameterizedFuncFactories_ResolvingTypeWithOneDependencyAtBothSidesOfCtorParameterList_Succeeds()
{
// Arrange
var container = new Container();
container.AllowResolvingParameterizedFuncFactories();
container.Register<ILogger, NullLogger>();
container.Register<ICommand, ConcreteCommand>();
// Act
var tupleFactory = container.GetInstance<Func<int, string, Tuple<ILogger, int, string, ICommand>>>();
var tuple = tupleFactory(0, null);
// Assert
AssertThat.IsInstanceOfType(typeof(NullLogger), tuple.Item1);
AssertThat.IsInstanceOfType(typeof(ConcreteCommand), tuple.Item4);
}
示例5: AllowResolvingParameterizedFuncFactories_ResolvingTypeWithoutDependencies_Succeeds
public void AllowResolvingParameterizedFuncFactories_ResolvingTypeWithoutDependencies_Succeeds()
{
// Arrange
var container = new Container();
container.AllowResolvingParameterizedFuncFactories();
// Act
var tupleFactory = container.GetInstance<Func<int, string, Tuple<int, string>>>();
var tuple = tupleFactory(1, "foo");
// Assert
Assert.AreEqual(1, tuple.Item1);
Assert.AreEqual("foo", tuple.Item2);
}