Files
social-media/backend/Modules/Contents/DependencyInjection.cs
2025-06-13 02:22:35 -04:00

28 lines
909 B
C#

using Hutopy.Modules.Contents.Data;
namespace Hutopy.Modules.Contents;
public static class DependencyInjection
{
public static WebApplicationBuilder AddContentModule(
this WebApplicationBuilder builder,
Action<DbContextOptionsBuilder>? configureAction = null)
{
builder.Services.AddDbContext<ContentsDbContext>(configureAction);
return builder;
}
public static async Task<IApplicationBuilder> UseContentModuleAsync(
this IApplicationBuilder app,
CancellationToken cancellationToken = default)
{
var scopeFactory = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>();
using var scope = scopeFactory.CreateScope();
await using var context = scope.ServiceProvider.GetRequiredService<ContentsDbContext>();
await context.Database.MigrateAsync(cancellationToken);
return app;
}
}