34 lines
805 B
C#
34 lines
805 B
C#
using LiteDB;
|
|
using WorkerService1.Domains;
|
|
|
|
namespace AutoDispathingWork.Utils;
|
|
|
|
public class StaticServiceProvider
|
|
{
|
|
public static void SetServiceProvider(IServiceProvider serviceProvider)
|
|
{
|
|
Current = serviceProvider;
|
|
}
|
|
|
|
private static IServiceProvider Current { get; set; }
|
|
|
|
public static T GetRequiredService<T>()
|
|
{
|
|
return Current.GetRequiredService<T>();
|
|
}
|
|
|
|
public static T? GetService<T>()
|
|
{
|
|
return Current.GetService<T>();
|
|
}
|
|
|
|
public static ILiteCollection<LogInfo> GetLogDb()
|
|
{
|
|
return Current.GetRequiredService<LiteDatabase>().GetCollection<LogInfo>();
|
|
}
|
|
|
|
public static ILogger GetLogger(string methodName)
|
|
{
|
|
return Current.GetRequiredService<ILoggerFactory>().CreateLogger(methodName);
|
|
}
|
|
} |