Refactor for .NET framework compatibility
Added preprocessor directives to conditionally include code for different .NET frameworks. Adjusted namespace declarations and organized the `Static` class for improved clarity and maintainability.
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
#if NETFRAMEWORK
|
||||
using System;
|
||||
#endif
|
||||
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DigitalData.Core.Infrastructure
|
||||
#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
|
||||
Reference in New Issue
Block a user