Refactor Static class to be generic
Updated the `Static` class in the `DigitalData.Core.Infrastructure` namespace to a generic version `Static<TEntity>`. Removed the original non-generic class and the `GetRepository<TEntity>` method. The new generic class provides a method to retrieve a repository for a specific entity type `TEntity`, enhancing type safety and usability.
This commit is contained in:
parent
5a3cbe8ecf
commit
ebf79309d1
@ -12,7 +12,7 @@ namespace DigitalData.Core.Infrastructure
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public class Static
|
public static class Static
|
||||||
{
|
{
|
||||||
private readonly static Lazy<IServiceCollection> LazyServices = new Lazy<IServiceCollection>(() => new ServiceCollection());
|
private readonly static Lazy<IServiceCollection> LazyServices = new Lazy<IServiceCollection>(() => new ServiceCollection());
|
||||||
|
|
||||||
@ -25,8 +25,11 @@ public class Static
|
|||||||
public static IServiceProvider Provider => LazyProvider.Value;
|
public static IServiceProvider Provider => LazyProvider.Value;
|
||||||
|
|
||||||
public static IRepository Repository => Provider.GetRequiredService<IRepository>();
|
public static IRepository Repository => Provider.GetRequiredService<IRepository>();
|
||||||
|
}
|
||||||
|
|
||||||
public static IRepository<TEntity> GetRepository<TEntity>() => Provider.GetRequiredService<IRepository<TEntity>>();
|
public static class Static<TEntity>
|
||||||
|
{
|
||||||
|
public static IRepository<TEntity> Repository() => Static.Provider.GetRequiredService<IRepository<TEntity>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user