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;
        //CALL IT LIKE THIS:
        //  ApiServerState apiServerState = (ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(ApiServerState));
        /*
        or is it like this??
         using (IServiceScope scope = provider.CreateScope())
                            {
                                AyContext ct = scope.ServiceProvider.GetRequiredService<AyContext>();
                                ApiServerState serverState = scope.ServiceProvider.GetRequiredService<ApiServerState>();
         */


        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>();
            }
        }



    }
}