using Microsoft.Extensions.DependencyInjection;
using xCommons.Extensions;
using xExceptions.Constants;
using xModels.Base;
using xModels.Interfaces;
namespace xModels.Extensions {
public static class DIExtensions {
///
/// Register an Specific Store in DI ...
///
/// DI service collection ...
/// an implementation of inetrface of store ...
/// service lifetime
/// implementation of TType ...
/// an inetrface which implements IXBaseStore
/// type of an instance of XBaseStorable
/// type of key of StorableItem
///
public static void AddXStore (
this IServiceCollection services,
TImplementation store,
ServiceLifetime lifeTime = ServiceLifetime.Singleton
)
where TImplementation : TType
where TType : IXBaseStore
where TStoreItemDto : XBaseStorableDto {
//
// Validate Args ...
if (store.IsNull ()) {
throw XException.InvalidArgs
.ToException ();
}
//
// Register Service in DI ...
services.Add (new ServiceDescriptor (typeof (TType), typeof (TImplementation), lifeTime));
}
}
}