AutoMapper 4.2 Injection with Autofac
See original GitHub issueCould anyone help make the following example work with Autofac?
public class AutoMapperRegistry : Registry
{
public AutoMapperRegistry()
{
var profiles =
from t in typeof (AutoMapperRegistry).Assembly.GetTypes()
where typeof (Profile).IsAssignableFrom(t)
select (Profile)Activator.CreateInstance(t);
var config = new MapperConfiguration(cfg =>
{
foreach (var profile in profiles)
{
cfg.AddProfile(profile);
}
});
For<MapperConfiguration>().Use(config);
For<IMapper>().Use(ctx => ctx.GetInstance<MapperConfiguration>().CreateMapper(ctx.GetInstance));
}
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:33 (2 by maintainers)
Top Results From Across the Web
Cannot resolve AutoMapper.IMapper using ...
While not exactly the answer, I had two regions in Startup, one for autofac and one for automapper. The builder.Build() was hidden and...
Read more >AutoMapper 4.2.1
Install AutoMapper via Nuget Package Manager. ... Also install Autofac , to demonstrate passing of mapper object through Dependency Injection.
Read more >Dependency Injection
There is a NuGet package to be used with the default injection mechanism described here and used in this project. You define the...
Read more >Autofac support for AutoMapper
Resolving object graphs resulting from using dependency injection is a common task that should be automated. My choice for this is Autofac ......
Read more >How to Use AutoMapper v10 in ASP.NET Web API 2 - YouTube
Automapper version 10 is the latest version, ... projects via dependency injection using the Unity dependency injection container in C#.
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 FreeTop 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
Top GitHub Comments
No idea, I’ve never used AutoFac.
This worked for me