Пример #1
0
        public GravatarMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, IOptions <GravatarOptions> options, ILoggerFactory loggerFactory)
        {
            _options             = options.Value;
            _fileProvider        = _options.FileProvider ?? ResolveFileProvider(hostingEnv);
            _next                = next;
            _defaultGravatarPath = _options.DefaultGravatarPath;
            //ensure that the provided default gravatar exists
            IFileInfo _fileInfo = _fileProvider.GetFileInfo(_defaultGravatarPath);

            if (!_fileInfo.Exists)
            {
                throw new ArgumentException($"Unable to find file {_defaultGravatarPath}");
            }
        }
Пример #2
0
        /// <summary>
        /// Enables gravatar path transformations logic with the given options
        /// </summary>
        /// <param name="app"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseGravatarMiddleware(this IApplicationBuilder app, GravatarOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(app.UseMiddleware <GravatarMiddleware>(Options.Create(options)));
        }