aspnet / BasicMiddleware

[Archived] Basic middleware components for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
169 stars 84 forks source link

HostFiltering should honor realtime options updates (inc. via configuration) #317

Closed DamianEdwards closed 6 years ago

DamianEdwards commented 6 years ago

It would be great to be able to change the configured hosts for the app without having to restart it. This likely requires a change in WebHost too, around here.

DamianEdwards commented 6 years ago

@Tratcher @muratg

Tratcher commented 6 years ago

Hmm, I don't think this is a feature we've supported in any middleware yet. We have reloadable config, but do we use it ourselves anywhere? Logging? @haok

DamianEdwards commented 6 years ago

We use it in logging for sure, including the Azure App Service integration. In trying this feature is found myself wanting to change the value and have the app honor it.

HaoK commented 6 years ago

It shouldn't be too hard to switch the middleware over, just need to hold onto IOptionsMonitor instead of caching the TOptions instance and use monitor.CurrentValue to access the options value.

        public HostFilteringMiddleware(RequestDelegate next, ILogger<HostFilteringMiddleware> logger, 
            IOptionsMonitor<HostFilteringOptions> options)
        {
            _next = next ?? throw new ArgumentNullException(nameof(next));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
            _options = options ?? throw new ArgumentNullException(nameof(options));
        }

        private HostFilteringOptions Options { get => _options.CurrentValue }
muratg commented 6 years ago

@DamianEdwards Do you want to timebox this (say "Small") in 2.1?

DamianEdwards commented 6 years ago

Yeah, it shouldn't be any harder than what @HaoK said plus ensuring the file config added by default flows changes (which I'm sure it already does).