如何使用 StructureMap 将 null 作为接口的默认实例传递?
我想使用 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 并将 null 参数传递给实例 但它没有任何答案。
I'd like to pass null as the default instance of my IFarmManager class using StructureMap. I've currently got the following in my Global.asax:
ObjectFactory.Initialize(x =>
{
x.ForRequestedType<IFarmManager>().TheDefault.Is.Object(null);
};
However, an ArgumentNullException is thrown at runtime:
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
Is it possible to use null as the default instance for an Interface?
I'm aware of this question: StructureMap and passing null parameter to instance but it doesn't have any answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来这样做的方法如下:
It seems the way to do it is as follows: