init
This commit is contained in:
commit
ab2e20f7e1
72 changed files with 2000 additions and 0 deletions
91
Femto.Modules.Blog/Module.cs
Normal file
91
Femto.Modules.Blog/Module.cs
Normal file
|
@ -0,0 +1,91 @@
|
|||
using System.Collections.Immutable;
|
||||
using Femto.Modules.Blog.Data;
|
||||
using Femto.Modules.Blog.Infrastructure;
|
||||
using Femto.Modules.Blog.Infrastructure.DbConnection;
|
||||
using Femto.Modules.Blog.Infrastructure.Integration;
|
||||
using Femto.Modules.Blog.Infrastructure.PipelineBehaviours;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
|
||||
namespace Femto.Modules.Blog;
|
||||
|
||||
public static class Module
|
||||
{
|
||||
public static void UseBlogModule(this IServiceCollection services, string connectionString)
|
||||
{
|
||||
OutboxMessageTypeRegistry.RegisterOutboxMessages(
|
||||
Contracts.Module.GetIntegrationEventTypes().ToImmutableDictionary()
|
||||
);
|
||||
|
||||
services.AddDbContext<BlogContext>(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(Module).Assembly);
|
||||
});
|
||||
|
||||
services.AddQuartz(q =>
|
||||
{
|
||||
q.AddMailmanJob();
|
||||
});
|
||||
|
||||
services.AddQuartzHostedService(options =>
|
||||
{
|
||||
options.WaitForJobsToComplete = true;
|
||||
});
|
||||
|
||||
services.SetupMediatrPipeline();
|
||||
|
||||
services.AddTransient<Outbox, Outbox>();
|
||||
services.AddTransient<IDbConnectionFactory>(_ => new DbConnectionFactory(connectionString));
|
||||
}
|
||||
|
||||
private static void SetupMediatrPipeline(this IServiceCollection services)
|
||||
{
|
||||
services.AddTransient(
|
||||
typeof(IPipelineBehavior<,>),
|
||||
typeof(SaveChangesPipelineBehaviour<,>)
|
||||
);
|
||||
}
|
||||
|
||||
private static void AddMailmanJob(this IServiceCollectionQuartzConfigurator q)
|
||||
{
|
||||
var jobKey = JobKey.Create(nameof(MailmanJob));
|
||||
|
||||
q.AddJob<MailmanJob>(jobKey)
|
||||
.AddTrigger(trigger =>
|
||||
trigger
|
||||
.ForJob(jobKey)
|
||||
.WithSimpleSchedule(schedule =>
|
||||
schedule.WithIntervalInSeconds(1).RepeatForever()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue