我在asp.net核心中使用Structure map作为我的di容器 当我想解决一些自动播放器解析器中的某些服务时,如下所示:
public class UserRolesResolver : IValueResolver<User, CurrentUserVeiwModel, List<string>>
{
private readonly AppUserManager _appUserManager;
public UserRolesResolver(AppUserManager appUserManager)
{
_appUserManager = appUserManager;
}
public List<string> Resolve(User source, CurrentUserVeiwModel destination, List<string> destMember, ResolutionContext context)
{
destination.Roles = AsyncHelpers.RunSync(() => _appUserManager.GetRolesAsync(source)).ToList();
return destination.Roles;
}
}
我得到的是
AutoMapperMappingException:无法创建类型的实例 AutomapperProfiles.UserRolesResolver
我还在Startup类中配置了automaticpper,如下所示:
services.AddAutoMapper(x =>
{
x.AddProfiles(Assembly.GetAssembly(typeof(OrderProfile)));
x.ConstructServicesUsing(type=> ServiceProvider.GetRequiredService(type));
});