Let's say I have custom ValueResolver
public class AssessmentAttendiesResolver : ValueResolver<List<int>, ICollection<Expert>>
{
private readonly IRepository<Expert> _expertRepository;
public AssessmentAttendiesResolver(IRepository<Expert> expertRepository)
{
_expertRepository = expertRepository;
}
protected override ICollection<Expert> ResolveCore(List<int> source)
{
return (ICollection<Expert>)_expertRepository.Query();
}
}
In my Global.asax I registered my custom resolver and override Mapper.Initialize method like this.
builder.RegisterAssemblyTypes(currentAssembly).AsClosedTypesOf(typeof(ValueResolver<,>)).AsSelf();
var container = builder.Build();
Mapper.Initialize(conf => conf.ConstructServicesUsing(container.Resolve));
And CreateMap
method
Mapper.CreateMap<AssessmentCreateRequestModel, Assessment>()
.ForMember(dest => dest.Attendies, opt => opt.ResolveUsing<AssessmentAttendiesResolver>().FromMember(item => item.Attendies));
When I run the code I get such exception
No scope with a Tag matching 'AutofacWebRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being requested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.
What should I change in order to successfully inject my repositories in my custom value resolver?