If we make any changes to appsettings.json
file, the IConfiguration
object will get updated on runtime.
But IOptions<MyClass>
wont get updated like that so you need to use IOptionsMonitor<MyClass>
or IOptionsSnapshot<MyClass>
. (All three of them are from the same namespace Microsoft.Extensions.Options
)
IOptionsMonitor<MyClass>
is singleton, so any mutation you make to this object will persist throughout the life of the application.
IOptionsSnapshot<MyClass>
is scoped, so any mutation you make to this object will be thrown out when the request finishes its life.
I learned this from Nick Chapsas in YouTube. URL
Keep coding.
Top comments (0)