public static IServiceCollection AddApiKeyMiddlewareSettings(this IServiceCollection builder, IConfigurationRoot config) { ApiKeyMiddlewareOptions apiKeyMiddlewareOptions = new ApiKeyMiddlewareOptions(); config.Bind("apiKeyMiddleware", apiKeyMiddlewareOptions); builder.AddSingleton <ApiKeyMiddlewareOptions>(apiKeyMiddlewareOptions); return(builder); }
public ApiKeyMiddleware(RequestDelegate next, ApiKeyMiddlewareOptions options) { _next = next; if (options == null) { throw new ArgumentNullException(nameof(options)); } if (string.IsNullOrWhiteSpace(options.ApiKey)) { throw new InvalidOperationException("API Key is null or empty string"); } _password = options.ApiKey; }