62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using System;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using AyaNova.Models;
|
|
|
|
namespace AyaNova.Util
|
|
{
|
|
/// <summary>
|
|
/// Shared service provider for static classes
|
|
/// </summary>
|
|
internal static class ServiceProviderProvider
|
|
{
|
|
private static IServiceProvider _provider;
|
|
internal static IServiceProvider Provider
|
|
{
|
|
get { return _provider; }
|
|
set { _provider = value; }
|
|
}
|
|
|
|
internal static IServiceScope Scope
|
|
{
|
|
get
|
|
{
|
|
return Provider.CreateScope();
|
|
}
|
|
}
|
|
|
|
internal static AyContext DBContext
|
|
{
|
|
get
|
|
{
|
|
return Scope.ServiceProvider.GetRequiredService<AyContext>();
|
|
}
|
|
}
|
|
|
|
internal static AyaNova.Api.ControllerHelpers.ApiServerState ServerState
|
|
{
|
|
get
|
|
{
|
|
return Scope.ServiceProvider.GetRequiredService<AyaNova.Api.ControllerHelpers.ApiServerState>();
|
|
}
|
|
}
|
|
|
|
internal static AyaNova.Util.IMailer Mailer
|
|
{
|
|
get
|
|
{
|
|
return Scope.ServiceProvider.GetRequiredService<AyaNova.Util.IMailer>();
|
|
}
|
|
}
|
|
|
|
// https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1
|
|
internal static System.Net.Http.IHttpClientFactory HttpClientFactory
|
|
{
|
|
get
|
|
{
|
|
return Scope.ServiceProvider.GetRequiredService<System.Net.Http.IHttpClientFactory>();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
} |