/// <summary> /// Adapts all registered services of the specified <paramref name="serviceType"/> /// using the specified <paramref name="adaptorType"/> /// returning as Adapted service of type <paramref name="targetType"/>. /// </summary> /// <param name="services">The services to add to.</param> /// <param name="serviceType">The type of services to Adapt.</param> /// <param name="adaptorType">The type to Adapt existing services with.</param> /// <param name="targetType">The resulting service type made available</param> /// <exception cref="MissingTypeRegistrationException">If no service of the specified <paramref name="serviceType"/> has been registered.</exception> /// <exception cref="ArgumentNullException">If either the <paramref name="services"/>, /// <paramref name="serviceType"/> or <paramref name="adaptorType"/> arguments are <c>null</c>.</exception> public static IServiceCollection Adapt(this IServiceCollection services, Type serviceType, Type adaptorType, Type targetType) { Preconditions.NotNull(services, nameof(services)); Preconditions.NotNull(serviceType, nameof(serviceType)); Preconditions.NotNull(adaptorType, nameof(adaptorType)); if (serviceType.IsOpenGeneric() && adaptorType.IsOpenGeneric()) { return(services.AdaptOpenGeneric(serviceType, adaptorType, targetType)); } return(services.AdaptDescriptors(serviceType, targetType, (adaptee) => adaptee.Adapt(targetType, adaptorType))); }