Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

IOptionsSnapshot is not working with singleton services #247

Closed
ductrantb opened this issue Dec 14, 2017 · 1 comment
Closed

IOptionsSnapshot is not working with singleton services #247

ductrantb opened this issue Dec 14, 2017 · 1 comment

Comments

@ductrantb
Copy link

ductrantb commented Dec 14, 2017

Hi friends,
I have a problem with IOptionsSnapshot. I was tried to use BackgroundServiceManagerConfigsFactory as a transient service to renew configs on change.

services.AddTransient<BackgroundServiceManagerConfigsFactory, BackgroundServiceManagerConfigsFactory>();
services.AddSingleton<BackgroundServiceManager, BackgroundServiceManager>();

The constructor of my configs factory was called on every request (by singleton service), but configs value was not changed.

public BackgroundServiceManagerConfigs Configs { get; protected set; }
public BackgroundServiceManagerConfigsFactory(IOptionsSnapshot<BackgroundServiceManagerConfigs> options)
{
        Configs = options.Value;
}

I tried to call this factory in a controller, it worked.
I used netcore 2.0 and Microsoft.Extensions.Options version 2.0.0.0
Thank you.

@aspnet-hello
Copy link

This issue was moved to dotnet/aspnetcore#2380

@aspnet aspnet locked and limited conversation to collaborators Jan 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants