Beispiel #1
0
 /// <summary>
 /// Creates a new instance of the CorrelationIdMiddleware.
 /// </summary>
 /// <param name="next">The next middleware in the pipeline.</param>
 /// <param name="accessor">The current <see cref="ICorrelationContextAccessor"/> (optional).</param>
 /// <param name="logger">The current <see cref="ILogger{T}"/> (optional).</param>
 /// <param name="options">The configuration options.</param>
 public CorrelationMiddleware(RequestDelegate next, ICorrelationContextAccessor accessor = default, ILogger <CorrelationMiddleware> logger = default, CorrelationOptions options = default)
 {
     _next     = next ?? throw new ArgumentNullException(nameof(next));
     _accessor = accessor;
     _logger   = logger;
     Options   = options ?? new CorrelationOptions();
     if (Options.CorrelationIdGenerator == null)
     {
         throw new ArgumentNullException($"{nameof(options)}.{nameof(options.CorrelationIdGenerator)}");
     }
 }
Beispiel #2
0
        /// <summary>
        /// Adds <see cref="CorrelationMiddleware"/> to ASP.NET pipeline.
        /// </summary>
        /// <param name="app">The current <see cref="IApplicationBuilder"/>.</param>
        /// <param name="configure">An <see cref="System.Action{T}"/> used to configure the <see cref="CorrelationOptions"/>.</param>
        /// <returns>The original <paramref name="app"/> targeted for chaining purposes.</returns>
        public static IApplicationBuilder UseCorrelationId(this IApplicationBuilder app, Action <CorrelationOptions> configure)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var options = new CorrelationOptions();

            configure.Invoke(options);

            return(UseMiddleware(app, options));
        }
Beispiel #3
0
 private static IApplicationBuilder UseMiddleware(IApplicationBuilder app, CorrelationOptions options)
 {
     return(app.UseMiddleware <CorrelationMiddleware>(Options.Create(options)));
 }
Beispiel #4
0
        /// <summary>
        /// Adds <see cref="CorrelationMiddleware"/> to ASP.NET pipeline.
        /// </summary>
        /// <param name="app">The current <see cref="IApplicationBuilder"/>.</param>
        /// <param name="options">The <see cref="CorrelationOptions"/> that control the middleware's behaviour.</param>
        /// <returns>The original <paramref name="app"/> for chaining purposes.</returns>
        public static IApplicationBuilder UseCorrelationId(this IApplicationBuilder app, CorrelationOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(UseMiddleware(app, options));
        }