12

我有一个 Autofac 容器,我希望能够检索所有注册的服务类型(不是实现类型,而是它们注册为的类型)。

我怎样才能从一个IComponentContext

4

2 回答 2

20

你可以使用这个:

var services =
    context.ComponentRegistry.Registrations.SelectMany(x => x.Services)
           .OfType<IServiceWithType>()
           .Select(x => x.ServiceType); 
于 2013-03-19T12:27:07.357 回答
-2

我是如何解决的

    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();
于 2017-03-04T17:01:16.027 回答