AspNetCoreRateLimit icon indicating copy to clipboard operation
AspNetCoreRateLimit copied to clipboard

Use IOptionsSnapshot instead of IOptions

Open msmolka opened this issue 8 years ago • 4 comments

It would be useful to settings be dynamically read when changed, so usage of IOptionsSnapshot could be used instead of IOptions

msmolka avatar Feb 22 '17 19:02 msmolka

to dynamically read one must support IOptionsMonitor, because IOptionsSnapshot is read once on class activation via DI, while Monitor can be dynamically changed in the same class instance.

justmara avatar Jun 24 '18 11:06 justmara

I am not quite sure what value will this enhancement bring (considering the possible consequences..).

What options would you want to change at runtime?

cristipufu avatar Feb 23 '19 18:02 cristipufu

Using IOptions causes configuration read once at startup. Using IOptionsSnapshot cause configuration read every DI resolve Using IOptionsMonitor allow change configuration dynamically without restart application.

msmolka avatar Feb 26 '19 11:02 msmolka

@msmolka Since MemoryCacheIpPolicyStore provide some method of which you can re set your policies by your self. MemoryCacheIpPolicyStore is singleton too, have a worker watch for option change, you can achive dynamic policies.

minhdanghuu avatar Jul 07 '22 03:07 minhdanghuu