示例#1
0
        /// <summary>
        /// Decorate all components implementing open generic service <paramref name="serviceType"/>.
        /// </summary>
        /// <param name="builder">Container builder.</param>
        /// <param name="decoratorType">The type of the decorator. Must be an open generic type, and accept a parameter
        /// of type <paramref name="serviceType"/>, which will be set to the instance being decorated.</param>
        /// <param name="serviceType">Service type being decorated. Must be an open generic type.</param>
        /// <param name="condition">A function that when provided with an <see cref="IDecoratorContext"/>
        /// instance determines if the decorator should be applied.</param>
        public static void RegisterGenericDecorator(
            this ContainerBuilder builder,
            Type decoratorType,
            Type serviceType,
            Func <IDecoratorContext, bool>?condition = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (decoratorType == null)
            {
                throw new ArgumentNullException(nameof(decoratorType));
            }

            if (serviceType == null)
            {
                throw new ArgumentNullException(nameof(serviceType));
            }

            var decoratorService = new DecoratorService(serviceType, condition);

            var genericRegistration = OpenGenericRegistrationExtensions
                                      .CreateGenericBuilder(decoratorType)
                                      .As(decoratorService);

            builder.RegisterServiceMiddlewareSource(new OpenGenericDecoratorMiddlewareSource(decoratorService, genericRegistration.RegistrationData, genericRegistration.ActivatorData));
        }
 public static IRegistrationBuilder <object, OpenGenericDecoratorActivatorData, DynamicRegistrationStyle> RegisterGenericDecorator(this ContainerBuilder builder, Type decoratorType, Type decoratedServiceType, object fromKey, object toKey)
 {
     if (builder == null)
     {
         throw new ArgumentNullException("builder");
     }
     if (decoratorType == null)
     {
         throw new ArgumentNullException("decoratorType");
     }
     if (decoratedServiceType == null)
     {
         throw new ArgumentNullException("decoratedServiceType");
     }
     return(OpenGenericRegistrationExtensions.RegisterGenericDecorator(builder, decoratorType, decoratedServiceType, fromKey, toKey));
 }
示例#3
0
        RegisterGenericDecorator(
            this ContainerBuilder builder,
            Type decoratorType,
            Type decoratedServiceType,
            object fromKey,
            object?toKey = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (decoratorType == null)
            {
                throw new ArgumentNullException(nameof(decoratorType));
            }

            if (decoratedServiceType == null)
            {
                throw new ArgumentNullException(nameof(decoratedServiceType));
            }

            return(OpenGenericRegistrationExtensions.RegisterGenericDecorator(builder, decoratorType, decoratedServiceType, fromKey, toKey));
        }
        RegisterGenericDecorator(
            this ContainerBuilder builder,
            [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type decoratorType,
            Type decoratedServiceType,
            object fromKey,
            object?toKey = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (decoratorType == null)
            {
                throw new ArgumentNullException(nameof(decoratorType));
            }

            if (decoratedServiceType == null)
            {
                throw new ArgumentNullException(nameof(decoratedServiceType));
            }

            return(OpenGenericRegistrationExtensions.RegisterGenericDecorator(builder, decoratorType, decoratedServiceType, fromKey, toKey));
        }
示例#5
0
 RegisterGeneric(this ContainerBuilder builder, Func <IComponentContext, Type[], IEnumerable <Parameter>, object> factory)
 {
     return(OpenGenericRegistrationExtensions.RegisterGeneric(builder, factory));
 }
示例#6
0
 RegisterGeneric(this ContainerBuilder builder, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type implementer)
 {
     return(OpenGenericRegistrationExtensions.RegisterGeneric(builder, implementer));
 }
示例#7
0
 RegisterGeneric(this ContainerBuilder builder, Type implementer)
 {
     return(OpenGenericRegistrationExtensions.RegisterGeneric(builder, implementer));
 }
 public static IRegistrationBuilder <object, ReflectionActivatorData, DynamicRegistrationStyle> RegisterGeneric(this ContainerBuilder builder, Type implementor)
 {
     return(OpenGenericRegistrationExtensions.RegisterGeneric(builder, implementor));
 }