using Microsoft.Extensions.DependencyInjection; using MaksIT.Persistence.Infrastructure; namespace MaksIT.Persistence.Extensions; /// /// Host startup helpers for FluentMigrator. /// public static class ServiceProviderExtensions { /// /// Runs when registered. /// Call from Program.cs before RunAsync. /// public static async Task EnsureLinq2DbMigratedAsync( this IServiceProvider serviceProvider, CancellationToken cancellationToken = default ) { await using var scope = serviceProvider.CreateAsyncScope(); var sp = scope.ServiceProvider; var run = sp.GetService(); if (run is not null) await run.RunAsync(cancellationToken).ConfigureAwait(false); } }