I am looking at a certain scenario in an application that i am currently working on
I want an Admin officer to be able to change system wide settings in an application.
public class ApplicationSettings
{
//bla bla bla
}
At startUp, I have the following binding
public static void RegisterServices(IKernel kernel)
{
kernel.Bind<ApplicationSettings>().ToSelf().InSingletonScope();
}
All is well and Good as I understand that the same instance of the application settings will be served for as long as the kernel is active
My question is this. What if I have to change the applicationsettings at runtime. And I want to automaticcally change the value of the ApplicationSettings instance in the kernel
Will it be possible to do something like this
public void ChangeSettings(IKernel kernel, ApplicationSettings setting)
{
var setting = kernel.Get<ApplicationSettings>();
//change the values of the instance
}
Question, How do i update the kernel binding so that subsequent references to the singleton instance will refer to the newly modified version
Thanks
What about Rebind<> ?
public void ChangeSettings(IKernel kernel, ApplicationSettings setting)
{
var setting = kernel.Get<ApplicationSettings>();
kernel.Rebind<ApplicationSettings>().ToConstant(setting);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With