Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

588 B
Raw Blame
using Microsoft.Extensions.DependencyInjection;

namespace Grand.Web.Common.Extensions;

public static class KeyedServiceHelper
{
    public static IList<string> GetKeyedServicesForInterface<TInterface>(IServiceCollection services)
    {
        ArgumentNullException.ThrowIfNull(services);

        return services
            .Where(service =>
                service.ServiceType == typeof(TInterface) &&
                service.IsKeyedService &&
                service.ServiceKey != null)
            .Select(service => service.ServiceKey.ToString())
            .ToList();
    }
}