我想使用StructureMap将null作为我的IFarmManager类的默认实例传递。我目前在Global.asax中有以下内容:
ObjectFactory.Initialize(x =>
{
x.ForRequestedType<IFarmManager>().TheDefault.Is.Object(null);
};
但是,在运行时抛出ArgumentNullException:
Value cannot be null.
Parameter name: anObject
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: anObject
是否可以使用null作为接口的默认实例?
我知道这个问题:StructureMap and passing null parameter to instance但它没有任何答案。
答案 0 :(得分:1)
似乎这样做的方法如下:
ObjectFactory.Initialize(x =>
{
x.ForRequestedType<IFarmManager>().TheDefault.Is.ConstructedBy(() => null);
});