/// <summary> /// Creates a new instance of the SendFileMiddleware. /// </summary> /// <param name="next">The next middleware in the pipeline.</param> /// <param name="hostingEnv">The <see cref="IHostingEnvironment"/> used by this middleware.</param> /// <param name="authService">The authorization service used to authorize the request.</param> /// <param name="pathProvider">The ILibraryPathProvider service used to determine paths to serve.</param> /// <param name="encoder">The <see cref="HtmlEncoder"/> used by the default <see cref="HtmlDirectoryFormatter"/>.</param> /// <param name="options">The configuration for this middleware.</param> public LibraryBrowserMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, IAuthorizationService authService, ILibraryPathProvider pathProvider, HtmlEncoder encoder, IOptions <LibraryBrowserOptions> options) { if (hostingEnv == null) { throw new ArgumentNullException(nameof(hostingEnv)); } if (encoder == null) { throw new ArgumentNullException(nameof(encoder)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } _next = next ?? throw new ArgumentNullException(nameof(next)); _options = options.Value; _authService = authService ?? throw new ArgumentNullException(nameof(authService)); _pathProvider = pathProvider ?? throw new ArgumentNullException(nameof(pathProvider)); _formatter = options.Value.Formatter ?? new LibraryBrowserFormtter(encoder); _prefixUrl = _options.RequestPath; }
/// <summary> /// Enable directory browsing with the given options /// </summary> /// <param name="app"></param> /// <param name="options"></param> /// <returns></returns> public static IApplicationBuilder UseLibraryBrowser(this IApplicationBuilder app, LibraryBrowserOptions options) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return(app.UseMiddleware <LibraryBrowserMiddleware>(Options.Create(options))); }