.Net Core Preview 5 Issue
See original GitHub issueWith the current .net core preview 5 i got an exception when building the automapper.
Exception
InvalidOperationException: No constructor for type ‘AutoMapper.Configuration.MapperConfigurationExpression+NamedProfile’ can be instantiated using services from the service container and default values.
Startup
services.AddScoped(e => e.GetRequiredService<MapperConfiguration>().CreateMapper());
services.AddSingleton(e => new MapperConfiguration(c =>
{
foreach (var profile in e.GetServices<Profile>())
{
c.AddProfile(profile);
}
}));
I also tried to use your extension, which fails too.
Exception
InvalidOperationException: Unable to resolve service for type ‘System.IO.DirectoryInfo’ while attempting to activate ‘Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository’.
Startup
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
Maybe this is not directly related to the automapper itself. But the question for me is, is there any plan to improve the wireup? Whouldn’t it be easier if the MapperConfiguration resolves the profiles at runtime itself via constructor injection?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
As it has been discussed many times before, profiles are singletons and allowing DI for them would be easily abused. Other than that, AM itself doesn’t do DI, only the extension does. About the error itself, feel free to investigate.
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.