diff --git a/Extensions/XDIKeyedServiceExtensions.cs b/Extensions/XDIKeyedServiceExtensions.cs
index a05a3f3..aae16cb 100644
--- a/Extensions/XDIKeyedServiceExtensions.cs
+++ b/Extensions/XDIKeyedServiceExtensions.cs
@@ -151,6 +151,74 @@ namespace xCommons.Extensions
lifetime));
}
+ ///
+ /// Register Specified Keyed Service ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void AddXKeyedService(
+ this IServiceCollection services,
+ string key,
+ TService instance,
+ ServiceLifetime lifetime = ServiceLifetime.Scoped
+ )
+ where TService : class
+ {
+ //
+ var erorr = new XError();
+
+ //
+ var isKeyValid = !key.IsNullOrEmpty();
+ var isInstanceValid = !instance.IsNull();
+ var isServicesValid = !services.IsNull();
+ var isServiceLifetimeValid = Enum.IsDefined(typeof(ServiceLifetime), lifetime);
+
+ //
+ if (!isKeyValid ||
+ !isInstanceValid ||
+ !isServicesValid ||
+ !isServiceLifetimeValid
+ )
+ {
+ //
+ if (!isKeyValid)
+ {
+ erorr.Message = $"Key not Provided ...";
+ }
+
+ //
+ if (!isInstanceValid)
+ {
+ erorr.Message = $"Instance not Provided ...";
+ }
+
+ //
+ if (!isServicesValid)
+ {
+ erorr.Message = $"Services not Provided ...";
+ }
+
+ //
+ if (!isServiceLifetimeValid)
+ {
+ erorr.Message = $"invalid Service Lifetime ...";
+ }
+
+ //
+ erorr.Id = (int)XException.InvalidArgs;
+ throw erorr.ToException();
+ }
+
+ //
+ services.Add(new ServiceDescriptor(
+ typeof(XKeyedService),
+ sp => new XKeyedService(key, instance),
+ lifetime));
+ }
+
///
/// Retrieve Registered XKeyedService ...
///