IValueResolver with parameterized constructor
See original GitHub issueI have written my own IValueResolver but I want it to have an interface injected at runtime from Ninject. How can I archive this?
Configure:
CreateMap<SourceEntity, DestModel>()
.ForMember(dest => dest.IsOk, opt => opt.ResolveUsing<MyResolver>());
Resolver:
public class MyResolver : IValueResolver<SourceEntity, DestModel, bool>
{
private readonly IMyFacadeService _myFacadeService;
public MyResolver (IMyFacadeService myFacadeService)
{
_myFacadeService= myFacadeService;
}
public bool Resolve(SourceEntity source, DestModel destination, bool destMember, ResolutionContext context)
{
var returnedBoolValue = Task.Run(async () => await _myFacadeService.CallSomeMethod(source)).Result;
return returnedBoolValue;
}
}
I had a look at the documentation where it says “ConstructBy” should be possible, but I cannot get that to work. It says return of opt.ResolveUsing<CustomResolver>() is void so I cannot add .ConstructedBy
Mapper.Initialize(cfg => cfg.CreateMap<Source, Destination>()
.ForMember(dest => dest.Total,
opt => opt.ResolveUsing<CustomResolver>().ConstructedBy(() => new CustomResolver())
);
But even if this was possible. How to actually add the Ninject Kernal binding for IMyFacadeService ?
Regards,
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Register ValueResolver with Parameterized Constructor ...
I have a custom IMemberValueResolver in my .NET Core 2.2 App that takes in a service and translates the source member to the...
Read more >How to use a value resolver when resolving a ctor parameter
I have an entity which has no property setters but has a parameterized constructor: public class Unit { public int Id { get;...
Read more >AutoMapper – passing parameter to custom resolver weird ...
There are ways to call Map that allow you to pass in values, so you don't need to try to finesse things with...
Read more >Dependency Injection
InSingletonScope(); // This teaches Ninject how to create automapper instances say if for instance // MyResolver has a constructor with a parameter that ......
Read more >Integrating AutoMapper with ASP.NET Core DI
When Injected into a constructor, I assign it to a private member by accessing mapperResolver.Mapper. Don't even have to call services.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I finally got it… here is the answer for anyone else looking, this is my ninject module for AutoMapper:
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.