Add repository access methods to Static class
This commit introduces two new properties in the `Static` class: `Repository` and `GetRepository<TEntity>()`. The `Repository` property allows retrieval of an `IRepository` instance from the service provider, while `GetRepository<TEntity>()` provides access to a specific `IRepository<TEntity>`. These additions improve the ease of accessing repository instances for data operations.
This commit is contained in:
parent
7689005a14
commit
d5a8619b4d
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace DigitalData.Core.Infrastructure
|
namespace DigitalData.Core.Infrastructure
|
||||||
@ -22,6 +23,10 @@ public class Static
|
|||||||
private static readonly Lazy<IServiceProvider> LazyProvider = new Lazy<IServiceProvider>(Services.BuildServiceProvider);
|
private static readonly Lazy<IServiceProvider> LazyProvider = new Lazy<IServiceProvider>(Services.BuildServiceProvider);
|
||||||
|
|
||||||
public static IServiceProvider Provider => LazyProvider.Value;
|
public static IServiceProvider Provider => LazyProvider.Value;
|
||||||
|
|
||||||
|
public static IRepository Repository => Provider.GetRequiredService<IRepository>();
|
||||||
|
|
||||||
|
public static IRepository<TEntity> GetRepository<TEntity>() => Provider.GetRequiredService<IRepository<TEntity>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user