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 189 02/04/2024
12.0.0 58 02/04/2024
11.0.0 61 02/04/2024
8.1.1 32 07/19/2024
8.1.0 36 07/19/2024
8.0.1 33 07/19/2024
8.0.0 35 07/19/2024
7.0.0 30 07/19/2024
6.1.1 23 07/19/2024
6.1.0 28 07/19/2024
6.0.0 27 07/19/2024
5.0.1 30 07/19/2024
4.0.1 32 07/19/2024
3.2.0 32 07/19/2024
3.1.0 34 07/19/2024
3.0.1 39 07/19/2024
2.0.1 25 07/19/2024
2.0.0 36 07/19/2024
1.2.0 37 07/19/2024
1.1.2 38 07/19/2024
1.1.0 33 07/19/2024
1.0.1-alpha 26 07/19/2024
1.0.0-alpha 30 07/19/2024