You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.
Not sure if this is intended behavior but it is confusing.
Consider the following example:
publicclassStartup{// This method gets called by the runtime. Use this method to add services to the container.// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940publicvoidConfigureServices(IServiceCollectionservices){
services.AddScoped<IConfigureOptions<ScopedOptions>,ScopedConfigureOptions>();}// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.publicvoidConfigure(IApplicationBuilderapp,IHostingEnvironmentenv){if(env.IsDevelopment()){
app.UseDeveloperExceptionPage();}
app.Run(async(context)=>{varoptionsSnapshot= context.RequestServices.GetService<IOptionsSnapshot<ScopedOptions>>();await context.Response.WriteAsync(optionsSnapshot.Value.I.ToString());});}}publicclassScopedConfigureOptions:IConfigureOptions<ScopedOptions>{privateint_i;privatestaticint_global;publicScopedConfigureOptions(){_i=_global++;}publicvoidConfigure(ScopedOptionsoptions){
options.I =_i;}}publicclassScopedOptions{publicintI{get;set;}}
I would expect OptionsSnapshot being scoped to initialize options instance using new instance of scoped IConfigureOptions every time instead last first one is cached forever (if IOptionsChangeTokenSource is not used)
Yeah this is a bug, the cache is singleton, so even though the snapshot is recreated, the cache'd value is returned.
The snapshot shouldn't be using the IOptionsCache at all, we should consider switching IOptionsMonitor over to the IOptionsCache/IOptionsFactory and having that be the official new way to get live options instances + do cache invaldations
Not sure if this is intended behavior but it is confusing.
Consider the following example:
I would expect
OptionsSnapshot
being scoped to initialize options instance using new instance of scopedIConfigureOptions
every time instead last first one is cached forever (ifIOptionsChangeTokenSource
is not used)@HaoK
The text was updated successfully, but these errors were encountered: