Use dependency injection in object mappers
See original GitHub issueA great feature of AutoMapper is the ability to use dependency injection from value resolvers and type converters (with the AutoMapper.Extensions.Microsoft.DependencyInjection package).
In a similar way, I would like to extend the ObjectMapper<object, string>
to use an internal service to convert string values to model objects and vice versa.
However, I cannot find a way to inject this service into my object mapper neatly.
It might be possible using the ResolutionContext
in the Map
overload, i.e. context.Options.CreateInstance<IService>()
but this is not available in the IsMatch() function.
Is using a service via dependency injection in an ObjectMapper object possible?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How do I convert an object using ObjectMapper and inject ...
As others already said, ObjectMapper does not do any dependency injection. But you can combine the @Autowired -ignoring ObjectMapper with some ...
Read more >Spring Boot : Does every dependency need to be injected?
Dependency injection is a design pattern in software engineering that involves injecting dependencies, or required objects or services, ...
Read more >MapStruct — Advanced Concepts and Dependency Injection
In such cases you can't use Interface as your mapper. Instead, use an Abstract class to declare your mapping methods as abstract methods....
Read more >Injecting Dependency in Mapper
In order to use feature toggles I would like to inject an instance of a class called FeatureManager which needs to be auto...
Read more >How to use .NET 6 AUTOMAPPER dependency injection
Learn how to implement AutoMapper with Dependency Injection and why we need this great library for mapping object to object.
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
Well, we could say it’s more specific so it should have a chance to run first, but really, the order of the mappers is a tricky subject. So we’d rather not mess with that. We didn’t change it for some time now, so I guess it’s the right order 😃 You can insert your own mapper wherever you want. In theory you can alter anything about the mappers collection, but as I’ve said, it’s tricky.
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.