40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using DigitalData.TaskFlow.Application.Options;
|
|
using FluentValidation;
|
|
using MediatR;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System.Reflection;
|
|
using DigitalData.TaskFlow.Application.Common.Behaviors;
|
|
|
|
namespace DigitalData.TaskFlow.Application;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddApplicationServices(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
var mediatROptions = configuration
|
|
.GetSection(MediatROptions.SectionName)
|
|
.Get<MediatROptions>();
|
|
|
|
services
|
|
.AddOptions<MediatROptions>()
|
|
.Bind(configuration.GetSection(MediatROptions.SectionName));
|
|
|
|
services.AddMediatR(config =>
|
|
{
|
|
config.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly);
|
|
|
|
if (!string.IsNullOrWhiteSpace(mediatROptions?.LuckyPennySoftLicenseKey))
|
|
{
|
|
config.LicenseKey = mediatROptions.LuckyPennySoftLicenseKey;
|
|
}
|
|
});
|
|
|
|
services.AddValidatorsFromAssembly(typeof(DependencyInjection).Assembly);
|
|
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
|
|
services.AddAutoMapper(_ => { }, Assembly.GetExecutingAssembly());
|
|
|
|
return services;
|
|
}
|
|
}
|