[英]Simple Injector register automapper
I would like to register Automapper with Simple Injector to inject it into the controller: 我想用Simple Injector注册Automapper,将它注入控制器:
public class MyController : BaseController
{
private IUnitOfWork unitOfWork;
private IMappingEngine mappingEngine;
public PatientController(IUnitOfWork _unitOfWork, IMappingEngine _mappingEngine)
{
this.unitOfWork = _unitOfWork;
this.mappingEngine = _mappingEngine;
}
}
However when I am trying to register it 但是,当我试图注册它
public static void Initialize()
{
//Code for registering our repository class and DI
var container = new Container();
container.Register<IUnitOfWork, UnitOfWork>();
container.Register<IMappingEngine, MappingEngine>();
container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
DependencyResolver.SetResolver(
new SimpleInjectorDependencyResolver(container));
}
I got an error: 我收到一个错误:
For the container to be able to create MappingEngine, it should contain exactly one public constructor, but it has 2.
要使容器能够创建MappingEngine,它应该只包含一个公共构造函数,但它有2个。
Parameter name: TImplementation.
参数名称:TImplementation。
What am I doing wrong? 我究竟做错了什么?
Simple Injector can't automatically auto-wire the MappingEngine
type for you, and it shouldn't, because this is a framework type and framework types should not be auto-wired, as you can read here . Simple Injector不能自动为您自动连接
MappingEngine
类型,它不应该,因为这是一个框架类型,框架类型不应该自动连接,你可以在这里阅读。
Instead, use manual wiring, as follows: 而是使用手动布线,如下所示:
var container = new Container();
container.RegisterSingle<IMappingEngine>(Mapper.Engine);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.