Added preprocessor directives to conditionally include code for different .NET frameworks. Adjusted namespace declarations and organized the `Static` class for improved clarity and maintainability.
37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
#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 static class Static
|
|
{
|
|
private readonly static Lazy<IServiceCollection> LazyServices = new Lazy<IServiceCollection>(() => new ServiceCollection());
|
|
|
|
public static IServiceCollection Services => LazyProvider.IsValueCreated
|
|
? LazyServices.Value
|
|
: throw new InvalidOperationException("Services cannot be accessed after the Provider has been created.");
|
|
|
|
private static readonly Lazy<IServiceProvider> LazyProvider = new Lazy<IServiceProvider>(Services.BuildServiceProvider);
|
|
|
|
public static IServiceProvider Provider => LazyProvider.Value;
|
|
|
|
public static IRepository Repository => Provider.GetRequiredService<IRepository>();
|
|
}
|
|
|
|
public static class Static<TEntity>
|
|
{
|
|
public static IRepository<TEntity> Repository() => Static.Provider.GetRequiredService<IRepository<TEntity>>();
|
|
}
|
|
|
|
#if NETFRAMEWORK
|
|
}
|
|
#endif |