public static IApplicationBuilder UsePrimeChecker(this IApplicationBuilder builder, PrimeCheckerOption options) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } var primeService = builder.ApplicationServices.GetService(typeof(PrimeService)) as PrimeService; return(builder.Use(next => new PrimeCheckerMiddleware(next, options, primeService).Invoke)); }
public PrimeCheckerMiddleware(RequestDelegate next, PrimeCheckerOption options, PrimeService primeService) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (primeService == null) { throw new ArgumentNullException(nameof(primeService)); } _next = next; _options = options; _primeService = primeService; }