2020-04-17 15:32:33 +02:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-04-29 12:11:35 +02:00
|
|
|
using Raven.Client.Documents;
|
2020-04-17 15:32:33 +02:00
|
|
|
using System;
|
|
|
|
|
using zero.Core;
|
|
|
|
|
using zero.Web.Mapper;
|
|
|
|
|
|
|
|
|
|
namespace zero.Web
|
|
|
|
|
{
|
|
|
|
|
public static class MapperServiceCollectionExtensions
|
|
|
|
|
{
|
2020-04-29 12:11:35 +02:00
|
|
|
public static IServiceCollection AddMapper<T>(this IServiceCollection services) where T : class, IMapper
|
2020-04-17 15:32:33 +02:00
|
|
|
{
|
|
|
|
|
return services.AddSingleton<IMapper, T>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IServiceCollection AddMapper<T>(this IServiceCollection services, Action<T> options) where T : class, IMapper, new()
|
|
|
|
|
{
|
|
|
|
|
return services.AddSingleton<IMapper, T>(factory =>
|
|
|
|
|
{
|
|
|
|
|
T mapper = new T();
|
|
|
|
|
options(mapper);
|
|
|
|
|
return mapper;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IServiceCollection AddMapper(this IServiceCollection services) => services.AddMapper<DefaultMapper>();
|
|
|
|
|
|
2020-04-29 12:11:35 +02:00
|
|
|
public static IServiceCollection AddMapper(this IServiceCollection services, Action<DefaultMapper> options)
|
|
|
|
|
{
|
|
|
|
|
return services.AddSingleton<IMapper, DefaultMapper>(factory =>
|
|
|
|
|
{
|
|
|
|
|
DefaultMapper mapper = new DefaultMapper(factory.GetService<IDocumentStore>());
|
|
|
|
|
options(mapper);
|
|
|
|
|
return mapper;
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-04-17 15:32:33 +02:00
|
|
|
}
|
|
|
|
|
}
|