示例#1
0
        /// <summary>
        /// Enables Client Ids for the request.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseClientId(this IApplicationBuilder app, ClientIdOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

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

            if (app.ApplicationServices.GetService(typeof(IClientIdContextFactory)) == null)
            {
                throw new InvalidOperationException("Unable to find the required services. You must call the AddClientId method in ConfigureServices in the application startup code.");
            }

            return(app.UseMiddleware <ClientIdMiddleware>(Options.Create(options)));
        }
 /// <summary>
 /// Creates a new instance of the CorrelationIdMiddleware.
 /// </summary>
 /// <param name="next">The next middleware in the pipeline.</param>
 /// <param name="options">The configuration options.</param>
 public ClientIdMiddleware(RequestDelegate next, IOptions <ClientIdOptions> options)
 {
     _next    = next ?? throw new ArgumentNullException(nameof(next));
     _options = options.Value ?? throw new ArgumentNullException(nameof(options));
 }