#if NETFRAMEWORK using System; #endif using DigitalData.Core.Abstraction.Application.Repository; using Microsoft.Extensions.DependencyInjection; namespace DigitalData.Core.Abstraction.Application #if NET ; #elif NETFRAMEWORK { #endif public interface IFactory : IServiceCollection, IServiceProvider { } public class Factory : ServiceCollection, IFactory, IServiceCollection, IServiceProvider { private readonly Lazy _rootProvider; private Factory() { _rootProvider = new Lazy(this.BuildServiceProvider); } public object #if NET ? #endif GetService(Type serviceType) { return _rootProvider.Value.GetService(serviceType); } public IRepository Repository => _rootProvider.Value.GetRequiredService(); public static readonly IFactory Shared = new Factory(); } public static class Factory { public static IRepository Repository() => Factory.Shared.GetRequiredService>(); } #if NETFRAMEWORK } #endif