28 lines
959 B
C#
28 lines
959 B
C#
using Hutopy.Modules.Messaging.Data;
|
|
|
|
namespace Hutopy.Modules.Messaging;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static WebApplicationBuilder AddMessagingModule(
|
|
this WebApplicationBuilder builder,
|
|
Action<DbContextOptionsBuilder>? configureAction = null)
|
|
{
|
|
builder.Services.AddDbContext<MessagingDbContext>(configureAction);
|
|
|
|
return builder;
|
|
}
|
|
|
|
public static async Task<IApplicationBuilder> UseMessagingModuleAsync(
|
|
this IApplicationBuilder app,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
IServiceScopeFactory scopeFactory = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>();
|
|
using IServiceScope scope = scopeFactory.CreateScope();
|
|
await using MessagingDbContext context = scope.ServiceProvider.GetRequiredService<MessagingDbContext>();
|
|
await context.Database.MigrateAsync(cancellationToken);
|
|
|
|
return app;
|
|
}
|
|
}
|