如何在Structuremap中配置Automapper

有人可以指导我如何在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!

qiuyue00 回答:如何在Structuremap中配置Automapper

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1248794.html

大家都在问