/// <summary> /// Registers the usage aware request loggers and decorators. /// </summary> /// <remarks> /// An instance of <see cref="IUsageAwareLogger"/> must be registered in the container. /// </remarks> /// <param name="decoratorBuilder">The CQS decorator builder.</param> /// <returns>The CQS decorator builder.</returns> public static SoftawareCqsDecoratorBuilder AddUsageAwareDecorators(this SoftawareCqsDecoratorBuilder decoratorBuilder) { decoratorBuilder.Services.AddTransient(typeof(UsageAwareLogger <,>)); decoratorBuilder.AddRequestHandlerDecorator(typeof(UsageAwareRequestHandlerDecorator <,>)); return(decoratorBuilder); }
/// <summary> /// Enables decorators for the softaware CQS infrastructure. /// </summary> /// <remarks> /// Decorators are applied in reverse order. This means decorators which are registered last will be executed first. /// Decorators which are registered earlier will be executed "closer" to the actual handler. /// </remarks> /// <param name="softawareCqsDecoratorBuilderAction">Provides an action to configure decorators.</param> /// <returns>The CQS builder.</returns> public SoftawareCqsBuilder AddDecorators(Action <SoftawareCqsDecoratorBuilder> softawareCqsDecoratorBuilderAction) { var decoratorBuilder = new SoftawareCqsDecoratorBuilder(this.Container); softawareCqsDecoratorBuilderAction.Invoke(decoratorBuilder); return(this); }
/// <summary> /// Registers the fluent validation request handler decorators as well as all validators from the specified assemblies. /// </summary> /// <param name="decoratorBuilder">The CQS decorator builder.</param> /// <param name="validatorTypesBuilderAction">The types builder for registering assemblies from where to find <see cref="IValidator{T}"/> instances.</param> /// <returns>The CQS decorator builder.</returns> public static SoftawareCqsDecoratorBuilder AddFluentValidationDecorators( this SoftawareCqsDecoratorBuilder decoratorBuilder, Action <SoftawareCqsTypesBuilder> validatorTypesBuilderAction) { var typesBuilder = new SoftawareCqsTypesBuilder(); validatorTypesBuilderAction.Invoke(typesBuilder); // Register all fluent validators which are available in the specified assemblies. decoratorBuilder.Services .Scan(scan => scan .FromAssemblies(typesBuilder.RegisteredAssemblies) .AddClasses(classes => classes.AssignableTo(typeof(IValidator <>))) .AsImplementedInterfaces() .WithTransientLifetime()); decoratorBuilder.AddRequestHandlerDecorator(typeof(FluentValidationRequestHandlerDecorator <,>)); return(decoratorBuilder); }
/// <summary> /// Registers the data annotations validation request handler decorators. /// </summary> /// <param name="decoratorBuilder">The CQS decorator builder.</param> /// <returns>The CQS decorator builder.</returns> public static SoftawareCqsDecoratorBuilder AddDataAnnotationsValidationDecorators(this SoftawareCqsDecoratorBuilder decoratorBuilder) { decoratorBuilder.Services.AddSingleton <IValidator>(new DataAnnotationsValidator()); decoratorBuilder.AddRequestHandlerDecorator(typeof(ValidationRequestHandlerDecorator <,>)); return(decoratorBuilder); }
/// <summary> /// Registers the transaction aware query handler decorator. /// </summary> /// <param name="decoratorBuilder">The CQS decorator builder.</param> /// <returns>The CQS decorator builder.</returns> public static SoftawareCqsDecoratorBuilder AddTransactionQueryHandlerDecorator(this SoftawareCqsDecoratorBuilder decoratorBuilder) { decoratorBuilder.AddRequestHandlerDecorator(typeof(TransactionAwareQueryHandlerDecorator <,>)); return(decoratorBuilder); }