【发布时间】:2013-07-03 07:44:11
【问题描述】:
当我为我的项目安装StructureMap 并使用时:
public class IndexController : Controller
{
private readonly IMapper<UserModel, UserDto> _mapper;
public IndexController(IMapper<UserModel, UserDto> mapper)
{
_mapper = mapper;
}
public ActionResult Index()
{
List<UserDto> userDb = UserDb.GetAll();
UserModel userModel = _mapper.Map(userDb[0]);
return View();
}
}
运行后出现服务器错误消息:
没有为此对象定义无参数构造函数。说明:一个 当前 web 执行过程中发生未处理的异常 要求。请查看堆栈跟踪以获取有关 错误以及它起源于代码的位置。 异常详细信息:System.MissingMethodException:没有为此对象定义无参数构造函数。 ...
但是我对依赖倒置的原理了解不多。请帮我解决这个问题。
这是ObjectFactory:
public static class IoC {
public static IContainer Initialize() {
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
// x.For<IExample>().Use<Example>();
});
return ObjectFactory.Container;
}
}
接下来我需要做什么?
【问题讨论】:
-
您是否按照安装说明:github.com/webadvanced/Structuremap-MVC3?也请发布您的
ObjectFactory配置! -
我已经按照你说的做了,但是这个错误仍然存在。接下来我需要做什么?
标签: c# asp.net-mvc-3 dependencies structuremap principles