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 866 02/04/2024
12.0.0 132 02/04/2024
11.0.0 151 02/04/2024
8.1.1 107 07/19/2024
8.1.0 116 07/19/2024
8.0.1 114 07/19/2024
8.0.0 108 07/19/2024
7.0.0 105 07/19/2024
6.1.1 105 07/19/2024
6.1.0 119 07/19/2024
6.0.0 100 07/19/2024
5.0.1 119 07/19/2024
4.0.1 103 07/19/2024
3.2.0 111 07/19/2024
3.1.0 109 07/19/2024
3.0.1 108 07/19/2024
2.0.1 107 07/19/2024
2.0.0 109 07/19/2024
1.2.0 102 07/19/2024
1.1.2 115 07/19/2024
1.1.0 112 07/19/2024
1.0.1-alpha 104 07/19/2024
1.0.0-alpha 106 07/19/2024