public static IFactoryCollection AddFirstLoader <TService>(this IFactoryCollection collection, bool singleton = true) where TService : class, IFirstLoader
 {
     if (collection.AllowAddServiceToCollection <TService>())
     {
         collection.Add(ServiceDescriptor.FirstLoader <TService>(singleton));
     }
     return(collection);
 }
 public static IFactoryCollection AddHostedService <TService>(this IFactoryCollection collection) where TService : class, IHostedService
 {
     if (collection.AllowAddServiceToCollection <TService>())
     {
         collection.Add(ServiceDescriptor.HostedService <TService>());
     }
     return(collection);
 }
 public static IFactoryCollection AddTransient <TService, TImpl>(this IFactoryCollection collection) where TService : class where TImpl : class, TService
 {
     if (collection.AllowAddServiceToCollection <TService, TImpl>())
     {
         collection.Add(ServiceDescriptor.Transient <TService, TImpl>());
     }
     return(collection);
 }
 public static IFactoryCollection AddSingleton <TService>(this IFactoryCollection collection) where TService : class
 {
     if (collection.AllowAddServiceToCollection <TService>())
     {
         collection.Add(ServiceDescriptor.Singleton <TService>());
     }
     return(collection);
 }
        public static IFactoryCollection AddHostedService <TService>(this IFactoryCollection collection, TService instance) where TService : class, IHostedService
        {
            if (instance == null)
            {
                throw new ArgumentNullException("HostedService instance cannot be null");
            }

            if (collection.AllowAddServiceToCollection <TService>(instance.GetType()))
            {
                collection.Add(ServiceDescriptor.HostedService <TService>());
            }

            return(collection);
        }
        public static IFactoryCollection AddSingleton <TService>(this IFactoryCollection collection, object instance) where TService : class
        {
            if (instance == null)
            {
                throw new ArgumentNullException("Singleton instance cannot be null");
            }

            if (collection.AllowAddServiceToCollection <TService>(instance.GetType(), true))
            {
                collection.Add(ServiceDescriptor.Singleton <TService>(instance));
            }

            return(collection);
        }