How to get all registered service types at Autofac

I have an Autofac container, and I would like to receive all registered types of services (not implementation types, but types that they registered as).

How can I get this information from IComponentContext ?

+7
source share
2 answers

You can use this:

 var services = context.ComponentRegistry.Registrations.SelectMany(x => x.Services) .OfType<IServiceWithType>() .Select(x => x.ServiceType); 
+14
source

How i resolved it

  var alldb = (from r in MasterDataFactory.Container.ComponentRegistry.Registrations let s = r.Services.Where(i => i is KeyedService).Select(i => i as KeyedService).FirstOrDefault() where s!=null && s.ServiceType==typeof(ISomeInterface) select s).ToList(); 
-2
source

All Articles