diff --git a/DigitalData.Core.Infrastructure/Static.cs b/DigitalData.Core.Infrastructure/Static.cs new file mode 100644 index 0000000..5348a14 --- /dev/null +++ b/DigitalData.Core.Infrastructure/Static.cs @@ -0,0 +1,29 @@ +#if NETFRAMEWORK +using System; +#endif + +using Microsoft.Extensions.DependencyInjection; + +namespace DigitalData.Core.Infrastructure +#if NET + ; +#elif NETFRAMEWORK + { +#endif + +public class Static +{ + private readonly static Lazy LazyServices = new Lazy(() => new ServiceCollection()); + + public static IServiceCollection Services => LazyProvider.IsValueCreated + ? LazyServices.Value + : throw new InvalidOperationException("Service collection is not available after the service provider has been built."); + + private static readonly Lazy LazyProvider = new Lazy(Services.BuildServiceProvider); + + public static IServiceProvider Provider => LazyProvider.Value; +} + +#if NETFRAMEWORK + } +#endif \ No newline at end of file