2013-03-19 8 views

Odpowiedz

14

Można to wykorzystać:

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

musiałem zmienić wybierz z czym w celu uzyskania z powrotem IEnumerable usług. var services = context.ComponentRegistry.Registrations.SelectMany (x => x.Services) .OfType () .Where (x => x.ServiceType); – NovaJoe

+1

@NovaJoe: To niemożliwe: Twój kod nie skompilowałby się, ponieważ 'ServiceType' nie jest' bool'. I nie miałoby to zbytniej sensu ... –

+0

Niestety, zapomniałem części instrukcji: var services = container.ComponentRegistry.Registrations.SelectMany (x => x.Services) .OfType (). (x => x.ServiceType == serviceType); Zauważ sprawdzanie równości dla określonego typu usługi. Mam również kontener zamiast kontekstu, który jest Autoontem IContainer. – NovaJoe

-2

Jak rozwiązane

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(); 
Powiązane problemy