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 11 06/07/2023
12.0.0 25 10/12/2022
11.0.0 8,219 06/27/2022
8.1.1 9,007 06/27/2022
8.1.0 25 06/27/2022
8.0.1 35 08/12/2022
8.0.0 43 06/27/2022
7.0.0 21 08/12/2022
6.1.1 46 06/27/2022
6.1.0 45 06/27/2022
6.0.0 22 06/27/2022
5.0.1 22 06/27/2022
4.0.1 20 08/12/2022
3.2.0 24 08/12/2022
3.1.0 24 08/12/2022
3.0.1 20 08/12/2022
2.0.1 46 07/02/2022
2.0.0 24 08/12/2022
1.2.0 16 06/27/2022
1.1.2 25 06/27/2022
1.1.0 28 06/27/2022
1.0.1-alpha 20 08/12/2022
1.0.0-alpha 36 08/09/2022