Method AddMapperion
- Namespace
- Mapperion
- Assembly
- Mapperion.Extensions.DependencyInjection.dll
AddMapperion(IServiceCollection, Action<IMapperConfigurationExpression>, ServiceLifetime)
Builds the configuration once and registers it, plus an IMapper bound to the container so converters, resolvers and mapping actions can take dependencies.
[RequiresUnreferencedCode("Mapping resolves members by reflection.")]
[RequiresDynamicCode("Mapping compiles plans at run time.")]
public static IServiceCollection AddMapperion(this IServiceCollection services, Action<IMapperConfigurationExpression> configure, ServiceLifetime mapperLifetime = ServiceLifetime.Scoped)
Parameters
servicesIServiceCollectionThe collection to add to.
configureAction<IMapperConfigurationExpression>The callback that declares maps and sets options.
mapperLifetimeServiceLifetimeHow long a mapper lives. Scoped by default, so a resolver may depend on scoped services; the compiled plans are shared across every mapper regardless, so this is cheap.
Returns
- IServiceCollection
The same collection, for chaining.
Exceptions
- ArgumentNullException
Either argument is null.
AddMapperion(IServiceCollection, params Assembly[])
Registers every profile found in the given assemblies, then the mapper.
[RequiresUnreferencedCode("Scanning assemblies for profiles is not compatible with trimming.")]
[RequiresDynamicCode("Mapping compiles plans at run time.")]
public static IServiceCollection AddMapperion(this IServiceCollection services, params Assembly[] assemblies)
Parameters
servicesIServiceCollectionThe collection to add to.
assembliesAssembly[]The assemblies to scan for profiles.
Returns
- IServiceCollection
The same collection, for chaining.
Exceptions
- ArgumentNullException
Either argument is null.
AddMapperion(IServiceCollection, params Type[])
Registers every profile found in the assemblies the given types come from, then the mapper. Handy when a marker type is easier to name than an assembly.
[RequiresUnreferencedCode("Scanning assemblies for profiles is not compatible with trimming.")]
[RequiresDynamicCode("Mapping compiles plans at run time.")]
public static IServiceCollection AddMapperion(this IServiceCollection services, params Type[] markers)
Parameters
servicesIServiceCollectionThe collection to add to.
markersType[]Types whose assemblies are scanned.
Returns
- IServiceCollection
The same collection, for chaining.
Exceptions
- ArgumentNullException
Either argument is null.