using WorkerService1; using WorkerService1.Domains; namespace AutoDispathingWork.Utils; public class StaticServiceProvider { public static void SetServiceProvider(IServiceProvider serviceProvider) { Current = serviceProvider; } public static IServiceProvider Current { get; set; } public static T GetRequiredService() { return Current.GetRequiredService(); } public static T? GetService() { return Current.GetService(); } public static void AddLog(LogInfo log) { using var scope = Current.CreateScope(); var dbContext = scope.ServiceProvider.GetRequiredService(); dbContext.LogInfos.Add(log); dbContext.SaveChanges(); } public static ILogger GetLogger(string methodName) { return Current.GetRequiredService().CreateLogger(methodName); } }