Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all registered service types in Autofac

Tags:

c#

autofac

I have an Autofac container and I would like to be able to retrieve all the registered service types (not the implementation types, but the types they are registered as).

How can I get this information from an IComponentContext?

like image 979
ChaseMedallion Avatar asked Mar 19 '13 12:03

ChaseMedallion


1 Answers

You can use this:

var services =
    context.ComponentRegistry.Registrations.SelectMany(x => x.Services)
           .OfType<IServiceWithType>()
           .Select(x => x.ServiceType); 
like image 99
Daniel Hilgarth Avatar answered Nov 12 '22 05:11

Daniel Hilgarth