AutoMapper.Extensions.Microsoft.DependencyInjection 12.0.1

AutoMapper extensions for Microsoft.Extensions.DependencyInjection

CI NuGet MyGet (dev)

Scans assemblies and:

  1. adds profiles to mapping configuration
  2. 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 transient
  • IValueConverter instances as transient
  • IValueResolver instances as transient
  • IMemberValueResolver instances as transient
  • IMappingAction 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

Version Downloads Last updated
12.0.1 21 04/24/2023
12.0.0 5 06/12/2023
11.0.0 8 07/03/2022
8.1.1 27 08/04/2021
8.1.0 8 07/24/2022
8.0.1 8 07/24/2022
8.0.0 9 07/24/2022
7.0.0 6 06/28/2022
6.1.1 6 07/11/2022
6.1.0 7 07/12/2022
6.0.0 6 07/11/2022
5.0.1 8 11/29/2019
4.0.1 5 07/11/2022
3.2.0 6 07/24/2022
3.1.0 8 07/24/2022
3.0.1 6 07/24/2022
2.0.1 27 07/24/2022
2.0.0 7 07/24/2022
1.2.0 5 07/24/2022
1.1.2 6 07/24/2022
1.1.0 6 07/24/2022
1.0.1-alpha 8 07/24/2022
1.0.0-alpha 9 07/24/2022