Initial Commit ...

This commit is contained in:
2024-01-25 04:37:38 +03:30
commit c5d69522a9
26 changed files with 1252 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
using Microsoft.Extensions.DependencyInjection;
using xCommons.Extensions;
using xExceptions.Constants;
using xModels.Base;
using xModels.Interfaces;
namespace xModels.Extensions {
public static class DIExtensions {
/// <summary>
/// Register an Specific Store in DI ...
/// </summary>
/// <param name="services">DI service collection ...</param>
/// <param name="store">an implementation of inetrface of store ...</param>
/// <param name="lifeTime">service lifetime</param>
/// <typeparam name="TImplementation">implementation of TType ...</typeparam>
/// <typeparam name="TType">an inetrface which implements IXBaseStore<TStoreItemDto, TKey></typeparam>
/// <typeparam name="TStoreItemDto">type of an instance of XBaseStorable<TKey></typeparam>
/// <typeparam name="TKey">type of key of StorableItem</typeparam>
/// <returns></returns>
public static void AddXStore<TImplementation, TType, TStoreItemDto, TKey> (
this IServiceCollection services,
TImplementation store,
ServiceLifetime lifeTime = ServiceLifetime.Singleton
)
where TImplementation : TType
where TType : IXBaseStore<TStoreItemDto, TKey>
where TStoreItemDto : XBaseStorableDto<TKey> {
//
// Validate Args ...
if (store.IsNull ()) {
throw XException.InvalidArgs
.ToException ();
}
//
// Register Service in DI ...
services.Add (new ServiceDescriptor (typeof (TType), typeof (TImplementation), lifeTime));
}
}
}