I added dependencies to my profile class:
public class MyModelMappingProfile : Profile
{
public MyModelMappingProfile(
IDependency1 dependencyOne, IDependencyTwo dependencyTwo)
When I start the service it complains System.MissingMethodException: No parameterless constructor defined for type 'MyModelMappingProfile'.
Found this solution, which solves the problem, but is very manual. Is there something more generic? Haven't found an answer in the docs
CodePudding user response:
https://jimmybogard.com/automapper-usage-guidelines/
X DO NOT inject dependencies into profiles
Profiles are static configuration, and injecting dependencies into them can cause unknown behavior at runtime. If you need to use a dependency, resolve it as part of your mapping operation. You can also have your extension classes (resolvers, type converters, etc.) take dependencies directly.