66 lines
2 KiB
C#
66 lines
2 KiB
C#
using Femto.Modules.Media.Data;
|
|
using Femto.Modules.Media.Infrastructure.Integration;
|
|
using Femto.Modules.Media.Infrastructure.PipelineBehaviours;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Femto.Modules.Media;
|
|
|
|
public static class MediaModule
|
|
{
|
|
public static void UseBlogModule(this IServiceCollection services, string connectionString)
|
|
{
|
|
OutboxMessageTypeRegistry.RegisterOutboxMessageTypesInAssembly(typeof(MediaModule).Assembly);
|
|
|
|
services.AddDbContext<MediaContext>(builder =>
|
|
{
|
|
builder.UseNpgsql(
|
|
connectionString,
|
|
o =>
|
|
{
|
|
o.MapEnum<OutboxEntryStatus>("outbox_status");
|
|
}
|
|
);
|
|
;
|
|
builder.UseSnakeCaseNamingConvention();
|
|
|
|
var loggerFactory = LoggerFactory.Create(b =>
|
|
{
|
|
b.AddConsole();
|
|
// .AddFilter(
|
|
// (category, level) =>
|
|
// category == DbLoggerCategory.Database.Command.Name
|
|
// && level == LogLevel.Debug
|
|
// );
|
|
});
|
|
|
|
builder.UseLoggerFactory(loggerFactory);
|
|
builder.EnableSensitiveDataLogging();
|
|
});
|
|
|
|
services.AddMediatR(c =>
|
|
{
|
|
c.RegisterServicesFromAssembly(typeof(MediaModule).Assembly);
|
|
});
|
|
|
|
services.SetupMediatrPipeline();
|
|
|
|
services.AddTransient<Outbox, Outbox>();
|
|
services.AddHostedService<Mailman>();
|
|
}
|
|
|
|
private static void SetupMediatrPipeline(this IServiceCollection services)
|
|
{
|
|
services.AddTransient(
|
|
typeof(IPipelineBehavior<,>),
|
|
typeof(DomainEventsPipelineBehaviour<,>)
|
|
);
|
|
|
|
services.AddTransient(
|
|
typeof(IPipelineBehavior<,>),
|
|
typeof(SaveChangesPipelineBehaviour<,>)
|
|
);
|
|
}
|
|
}
|