AutoMapper.Extensions.Microsoft.DependencyInjection 12.0.1
AutoMapper extensions for Microsoft.Extensions.DependencyInjection
Scans assemblies and:
- adds profiles to mapping configuration
- adds value resolvers, member value resolvers, type converters to the container.
To use, with an IServiceCollection
instance and one or more assemblies:
services.AddAutoMapper(assembly1, assembly2 /*, ...*/);
or marker types:
services.AddAutoMapper(type1, type2 /*, ...*/);
This registers AutoMapper:
- As a singleton for the
MapperConfiguration
- As a transient instance for
IMapper
ITypeConverter
instances as transientIValueConverter
instances as transientIValueResolver
instances as transientIMemberValueResolver
instances as transientIMappingAction
instances as transient
Mapping configuration is static as it is the root object that can create an IMapper
.
Mapper instances are registered as transient. You can configure this with the serviceLifetime
parameter. Be careful changing this, as Mapper
takes a dependency on a factory method to instantiate the other extensions.
Mapper.Map usage
To map at runtime, add a dependency on IMapper
:
public class EmployeesController {
private readonly IMapper _mapper;
public EmployeesController(IMapper mapper)
=> _mapper = mapper;
// use _mapper.Map to map
}
ProjectTo usage
Starting with 8.0 you can use IMapper.ProjectTo
. The old ProjectTo
is an extension method and does not have dependency injection available. Pass an IConfigurationProvider
instance directly:
var orders = await dbContext.Orders
.ProjectTo<OrderDto>(_configurationProvider)
.ToListAsync();
Or you can use an IMapper
instance:
var orders = await dbContext.Orders
.ProjectTo<OrderDto>(_mapper.ConfigurationProvider)
.ToListAsync();
No packages depend on AutoMapper.Extensions.Microsoft.DependencyInjection.
.NET Standard 2.1
- AutoMapper (= 12.0.1)
- Microsoft.Extensions.Options (>= 6.0.0)
Version | Downloads | Last updated |
---|---|---|
12.0.1 | 33 | 06/07/2023 |
12.0.0 | 42 | 10/12/2022 |
11.0.0 | 9,334 | 06/27/2022 |
8.1.1 | 10,114 | 06/27/2022 |
8.1.0 | 46 | 06/27/2022 |
8.0.1 | 57 | 08/12/2022 |
8.0.0 | 71 | 06/27/2022 |
7.0.0 | 40 | 08/12/2022 |
6.1.1 | 76 | 06/27/2022 |
6.1.0 | 70 | 06/27/2022 |
6.0.0 | 41 | 06/27/2022 |
5.0.1 | 46 | 06/27/2022 |
4.0.1 | 41 | 08/12/2022 |
3.2.0 | 42 | 08/12/2022 |
3.1.0 | 51 | 08/12/2022 |
3.0.1 | 41 | 08/12/2022 |
2.0.1 | 68 | 07/02/2022 |
2.0.0 | 39 | 08/12/2022 |
1.2.0 | 33 | 06/27/2022 |
1.1.2 | 42 | 06/27/2022 |
1.1.0 | 48 | 06/27/2022 |
1.0.1-alpha | 36 | 08/12/2022 |
1.0.0-alpha | 61 | 08/09/2022 |