Add AutoMapper profile discovery support
This commit is contained in:
parent
1447265994
commit
81439cc2ad
|
|
@ -1,4 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
|
@ -19,6 +22,13 @@ namespace Elsa.Extensions
|
|||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddAutoMapperProfiles(this IServiceCollection services, IEnumerable<Assembly> assemblies) =>
|
||||
services.Scan(scan => scan.FromAssemblies(assemblies).AddClasses(classes => classes.AssignableTo<Profile>()).As<Profile>().WithTransientLifetime());
|
||||
|
||||
public static IServiceCollection AddAutoMapperProfiles(this IServiceCollection services, params Assembly[] assemblies) => services.AddAutoMapperProfiles(assemblies.AsEnumerable());
|
||||
public static IServiceCollection AddAutoMapperProfiles(this IServiceCollection services, Assembly assembly) => AddAutoMapperProfiles(services, new[] { assembly });
|
||||
public static IServiceCollection AddAutoMapperProfiles<TAssemblyMarkerType>(this IServiceCollection services) => services.AddAutoMapperProfiles(typeof(TAssemblyMarkerType).Assembly);
|
||||
|
||||
public static IConfigurationProvider CreateAutoMapperConfiguration(this IServiceProvider serviceProvider)
|
||||
{
|
||||
var profiles = serviceProvider.GetServices<Profile>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue