问题描述
有人可以指导我如何在Automapper
中配置Structuremap
吗?目前,我有将使用IMapper
的服务。
public class RequestService : IRequestService
{
private readonly IMapper _mapper;
private readonly IRepositoryWrapper _repositoryWrapper;
public RequestService(IMapper mapper,IRepositoryWrapper repositoryWrapper)
{
_mapper = mapper;
_repositoryWrapper = repositoryWrapper;
}
public void GetSomething()
{
var result = _repositoryWrapper.RequestRepository.GetAll();
_mapper.Map<RequestDto>(result);
}
}
另一方面,这是我的Registry
。这也是我配置自动映射器的地方。
public class InfrastructureRegistry : Registry
{
public InfrastructureRegistry()
{
var mapperConfiguration = new MapperConfiguration(cfg => {
cfg.AddProfile(typeof(MapperProfile));
});
var mapper = mapperConfiguration.CreateMapper();
For<IMapper>().Use(mapper);
Scan(
scan => {
scan.TheCallingAssembly();
scan.AssemblyContainingType<IRequestService>();
scan.AssemblyContainingType<IRepositoryWrapper>();
scan.WithDefaultConventions();
});
For<IRequestService>().Use<RequestService>();
For<IRepositoryWrapper>().Use<RepositoryWrapper>();
}
}
在测试过程中,我收到此错误消息。
StructureMap.StructureMapConfigurationException: 'No default Instance is registered and cannot be automatically determined for type 'AutoMapper.IMapper'
我正在使用以下版本:
- Automapper = 10.1.1
- StructureMap.WebApi2 = 3.0.4.125
- StructureMap = 3.0.4.125
希望有人可以对此进行指导。
TIA!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)