コード例 #1
0
 public CorrelationMiddleware(
     IOptions <CorrelationOptions> correlationOptions,
     ILogger <CorrelationMiddleware>?correlationLogger)
 {
     options = correlationOptions?.Value ?? throw new ArgumentNullException(nameof(correlationOptions));
     logger  = correlationLogger;
 }
コード例 #2
0
        /// <summary>
        /// Injects correlation middleware.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/> to act on.</param>
        /// <param name="options">Custom <see cref="CorrelationOptions"/>.</param>
        /// <returns><paramref name="services"/> to allow chained calls.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> or <paramref name="services"/> is null.</exception>
        public static IServiceCollection AddCorrelation(this IServiceCollection services, CorrelationOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            services?.AddSingleton(Options.Create(options));
            return(services?.AddSingleton <CorrelationMiddleware>() ?? throw new ArgumentNullException(nameof(services)));
        }