Autofac Registration:
builder.RegisterType<RelatedTransportMangerResolver>().AsSelf();
builder.Register(context => new MapperConfiguration(cfg =>
{
cfg.AddProfile<AssetMapperProfile>();
})).AsSelf().SingleInstance();
builder.Register(c => c.Resolve<MapperConfiguration>().CreateMapper(c.Resolve))
.As<IMapper>()
.InstancePerLifetimeScope();
Map that uses the custom value resolver:
CreateMap<TrafficArea, TrafficAreaViewModel>()
.ForMember(ta => ta.TransportManagers,
opt => opt.MapFrom(ta =>
ta.TrafficAreaKeyContacts
.Where(kc => kc.KeyContactGroup.HasFlag(KeyContactGroup.TransportManager))
.Select(atr => atr.KeyContact)))
.ForMember(ta => ta.RelatedTransportManagers,
opt => opt.MapFrom<RelatedTransportMangerResolver>());
Error being returned is:
This resolve operation has already ended. When registering components using lambdas, the IComponentContext 'c' parameter to the lambda cannot be stored. Instead, either resolve IComponentContext again from 'c', or resolve a Func<> based factory to create subsequent components from.
Any ideas on how to fix this error?