38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using AutoMapper;
|
|
|
|
namespace Taloyhtio.GeneralApi.Core.Infrastructure.AutoMapper
|
|
{
|
|
public class AutoMapperConfiguration
|
|
{
|
|
// public static Func<Type, object> CreateDependencyCallback = (type) => Activator.CreateInstance(type);
|
|
|
|
|
|
public static void Configure()
|
|
{
|
|
Mapper.Initialize(x =>
|
|
{
|
|
// x.ConstructServicesUsing(type => CreateDependencyCallback(type));
|
|
GetProfiles().ToList().ForEach(type => x.AddProfile((Profile) Activator.CreateInstance(type)));
|
|
});
|
|
}
|
|
|
|
private static IEnumerable<Type> GetProfiles()
|
|
{
|
|
foreach (Type type in typeof (AutoMapperConfiguration).Assembly.GetTypes())
|
|
{
|
|
if (!type.IsAbstract && typeof (Profile).IsAssignableFrom(type))
|
|
yield return type;
|
|
}
|
|
}
|
|
|
|
// void IRequiresConfigurationOnStartup.Configure()
|
|
// {
|
|
// Configure();
|
|
//
|
|
// AutoMappedViewResult.Map = (a, b, c) => Mapper.Map(a, b, c);
|
|
// }
|
|
}
|
|
} |