/// <summary> /// Creates a new instance of <see cref="MiniProfilerMiddleware"/> /// </summary> /// <param name="next">The delegate representing the next middleware in the request pipeline.</param> /// <param name="hostingEnvironment">The Hosting Environment.</param> /// <param name="options">The middleware options, containing the rules to apply.</param> /// <exception cref="ArgumentNullException">Throws when <paramref name="next"/>, <paramref name="hostingEnvironment"/>, or <paramref name="options"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Throws when <see cref="MiniProfilerOptions.RouteBasePath"/> is <c>null</c> or empty.</exception> public MiniProfilerMiddleware( RequestDelegate next, IHostingEnvironment hostingEnvironment, MiniProfilerOptions options) { _next = next ?? throw new ArgumentNullException(nameof(next)); _env = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); Options = options ?? throw new ArgumentNullException(nameof(options)); if (string.IsNullOrEmpty(Options.RouteBasePath)) { throw new ArgumentException("BasePath cannot be empty", nameof(Options.RouteBasePath)); } var basePath = Options.RouteBasePath; // Example transform: ~/mini-profiler-results/ to /mini-profiler-results if (basePath.StartsWith("~/", StringComparison.Ordinal)) { basePath = basePath.Substring(1); } if (basePath.EndsWith("/", StringComparison.Ordinal) && basePath.Length > 2) { basePath = basePath.Substring(0, basePath.Length - 1); } MatchPath = new PathString(basePath); BasePath = new PathString(basePath.EnsureTrailingSlash()); Embedded = new EmbeddedProvider(Options, _env); // A static reference back to this middleware for property access. // Which is probably a crime against humanity in ways I'm ignorant of. Current = this; }
/// <summary> /// Creates a new instance of <see cref="MiniProfilerMiddleware"/> /// </summary> /// <param name="next">The delegate representing the next middleware in the request pipeline.</param> /// <param name="hostingEnvironment">The Hosting Environment.</param> /// <param name="options">The middleware options, containing the rules to apply.</param> /// <exception cref="ArgumentNullException">Throws when <paramref name="next"/>, <paramref name="hostingEnvironment"/>, or <paramref name="options"/> is <c>null</c>.</exception> public MiniProfilerMiddleware( RequestDelegate next, IHostingEnvironment hostingEnvironment, IOptions <MiniProfilerOptions> options) { _next = next ?? throw new ArgumentNullException(nameof(next)); _env = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _options = options ?? throw new ArgumentNullException(nameof(options)); if (string.IsNullOrEmpty(Options.RouteBasePath)) { throw new ArgumentException("RouteBasePath cannot be empty", nameof(Options.RouteBasePath)); } Embedded = new EmbeddedProvider(_options, _env); }