/// <summary> /// Adapts all registered services of type <typeparam name="TAdaptee"/> /// using the specified type <typeparam name="TAdapter"/>. /// returning as Adapted service of type <typeparam name="TTarget"/> /// </summary> /// <param name="services">The services to add to.</param> /// <exception cref="MissingTypeRegistrationException">If no service of the type <typeparamref name="TAdaptee"/> has been registered.</exception> /// <exception cref="ArgumentNullException">If the <paramref name="services"/> argument is <c>null</c>.</exception> public static IServiceCollection Adapt <TAdaptee, TAdapter, TTarget>(this IServiceCollection services) where TAdapter : TTarget { Preconditions.NotNull(services, nameof(services)); return(services.AdaptDescriptors(typeof(TAdaptee), typeof(TTarget), (adaptee) => adaptee.Adapt(typeof(TAdapter), typeof(TTarget)))); }
/// <summary> /// Adapts all registered services of type <typeparamref name="TService"/> /// using the <paramref name="decorator"/> function. /// </summary> /// <typeparam name="TService">The type of services to Adapt.</typeparam> /// <typeparam name="TTarget">The resulting service type made available</typeparam> /// <param name="services">The services to add to.</param> /// <param name="decorator">The decorator function.</param> /// <exception cref="MissingTypeRegistrationException">If no service of <typeparamref name="TService"/> has been registered.</exception> /// <exception cref="ArgumentNullException">If either the <paramref name="services"/> /// or <paramref name="decorator"/> arguments are <c>null</c>.</exception> public static IServiceCollection Adapt <TService, TTarget>(this IServiceCollection services, Func <TService, TTarget> decorator) { Preconditions.NotNull(services, nameof(services)); Preconditions.NotNull(decorator, nameof(decorator)); return(services.AdaptDescriptors(typeof(TService), typeof(TTarget), (adaptee) => adaptee.Adapt(typeof(TTarget), typeof(TTarget)))); }
/// <summary> /// Adapts all registered services of the specified <paramref name="serviceType"/> /// using the <paramref name="adapter"/> function. /// </summary> /// <param name="services">The services to add to.</param> /// <param name="serviceType">The type of services to Adapt.</param> /// <param name="targetType">The resulting service type made available</param> /// <param name="adapter">The decorator function.</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="adapter"/> arguments are <c>null</c>.</exception> public static IServiceCollection Adapt(this IServiceCollection services, Type serviceType, Type targetType, Func <object, object> adapter) { Preconditions.NotNull(services, nameof(services)); Preconditions.NotNull(serviceType, nameof(serviceType)); Preconditions.NotNull(adapter, nameof(adapter)); return(services.AdaptDescriptors(serviceType, targetType, (adaptee) => adaptee.Adapt(adapter))); }
/// <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))); }