using System; using System.Collections; using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using xCommons.Helpers; namespace xCommons.Extensions { public static class ServiceProviderExtensions { /// /// Get all registered /// /// /// public static Dictionary GetAllServiceDescriptors (this IServiceProvider provider) { // if (provider is ServiceProvider serviceProvider) { // var result = new Dictionary (); // var engine = serviceProvider.GetFieldValue ("_engine"); var callSiteFactory = engine.GetPropertyValue ("CallSiteFactory"); var descriptorLookup = callSiteFactory.GetFieldValue ("_descriptorLookup"); if (descriptorLookup is IDictionary dictionary) { foreach (DictionaryEntry entry in dictionary) { result.Add ((Type) entry.Key, (ServiceDescriptor) entry.Value.GetPropertyValue ("Last")); } } // return result; } // throw new NotSupportedException ($"Type '{provider.GetType()}' is not supported!"); } } }