question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use dependency injection in object mappers

See original GitHub issue

A 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lbargaoanucommented, Oct 17, 2018

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.

0reactions
lock[bot]commented, May 5, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found