using Hutopy.Modules.Messaging.Data; using Hutopy.Modules.Tipping.Contracts; using Hutopy.Modules.Tipping.Data; using Hutopy.Modules.Tipping.Services; namespace Hutopy.Modules.Tipping; public static class DependencyInjection { public static WebApplicationBuilder AddTippingModule( this WebApplicationBuilder builder, Action? configureAction = null) { builder.Services.AddDbContext(configureAction); builder.Services.AddTransient(); return builder; } public static async Task UseTippingModuleAsync( this IApplicationBuilder app, CancellationToken cancellationToken = default) { IServiceScopeFactory scopeFactory = app.ApplicationServices.GetRequiredService(); using IServiceScope scope = scopeFactory.CreateScope(); await using MessagingDbContext context = scope.ServiceProvider.GetRequiredService(); await context.Database.MigrateAsync(cancellationToken); return app; } }