40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
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 const string LuckyPennySoftLicenseKeySection = "LuckyPennySoftLicenseKey";
|
|
|
|
public static IServiceCollection AddApplicationServices(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
var lpSoftLicenseKey = configuration[LuckyPennySoftLicenseKeySection];
|
|
var hasLpSoftLicenseKey = !string.IsNullOrWhiteSpace(lpSoftLicenseKey);
|
|
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
|
|
services.AddMediatR(config =>
|
|
{
|
|
config.RegisterServicesFromAssembly(assembly);
|
|
|
|
if (hasLpSoftLicenseKey)
|
|
config.LicenseKey = lpSoftLicenseKey;
|
|
});
|
|
|
|
services.AddValidatorsFromAssembly(assembly);
|
|
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
|
|
services.AddAutoMapper(config =>
|
|
{
|
|
if (hasLpSoftLicenseKey)
|
|
config.LicenseKey = lpSoftLicenseKey;
|
|
}, assembly);
|
|
|
|
return services;
|
|
}
|
|
}
|