IEnumerable <IComponentRegistration> IRegistrationSource.RegistrationsFor(Service service, Func <Service, IEnumerable <IComponentRegistration> > registrationAccessor) { if (!(service is IServiceWithType serviceWithType)) { return(_inner.RegistrationsFor(service, registrationAccessor)); } var serviceType = serviceWithType.ServiceType; if (!serviceType.IsGenericType) { return(_inner.RegistrationsFor(service, registrationAccessor)); } var genericService = serviceWithType.ChangeType(serviceType.GetGenericTypeDefinition()); if (!_services.Contains(genericService)) { return(_inner.RegistrationsFor(service, registrationAccessor)); } var specificServices = _services.Cast <IServiceWithType>().Select(svc => svc.ChangeType(serviceType)); return(_inner.RegistrationsFor(new KeyedService(DecoratorKey.Locator, serviceType), registrationAccessor) .Select(registration => new DecoratorComponentRegistration(registration, specificServices, _parameter))); }
public IEnumerable <IComponentRegistration> RegistrationsFor(Autofac.Core.Service service, Func <Autofac.Core.Service, IEnumerable <IComponentRegistration> > registrationAccessor) { var components = _source.RegistrationsFor(service, registrationAccessor); foreach (var c in components) { var defs = c.Target.Services .OfType <TypedService>() .Select(x => x.ServiceType.GetGenericTypeDefinition()); if (defs.Any(_types.Contains)) { yield return(c); } } }
private ServiceRegistrationInfo GetInitializedServiceInfo(Service service) { ServiceRegistrationInfo serviceInfo = this.GetServiceInfo(service); if (!serviceInfo.IsInitialized) { if (!serviceInfo.IsInitializing) { serviceInfo.BeginInitialization(this._dynamicRegistrationSources); } while (serviceInfo.HasSourcesToQuery) { Func <IRegistrationSource, bool> predicate = null; IRegistrationSource next = serviceInfo.DequeueNextSource(); foreach (IComponentRegistration registration in next.RegistrationsFor(service, new Func <Service, IEnumerable <IComponentRegistration> >(this.RegistrationsFor))) { foreach (Service service2 in registration.Services) { ServiceRegistrationInfo info2 = this.GetServiceInfo(service2); if (!info2.IsInitialized) { if (!info2.IsInitializing) { if (predicate == null) { predicate = src => src != next; } info2.BeginInitialization(this._dynamicRegistrationSources.Where <IRegistrationSource>(predicate)); } else { info2.SkipSource(next); } } } this.AddRegistration(registration, true); } } serviceInfo.CompleteInitialization(); } return(serviceInfo); }
public IEnumerable <IComponentRegistration> RegistrationsFor(Service service, Func <Service, IEnumerable <ServiceRegistration> > registrations) { return(parent.RegistrationsFor(service, registrations)); }