Hi I have a situation where I need to update a service that I have injected.
When I first launch the app I have something like
public class MyService:IMyService
{
public string ValueAPopulatedBeforeLogin { get; set; }
public string ValueBPopulatedBeforeLogin { get; set; }
public string ValueCPopulatedAfterLogin { get; set; }
}
container<IMyService,MyService>();
Now I need to update MyService but doing
container.ClearCache(typeOf(IMyService));
container.UseInstance(MyService); //with new ValueC updated value
however the new property has not been updated.
How do you update an already injected service? Is this possible?
thanks
Update
Which leads to a conclusion and hopefully I am wrong - I cannot change the already injected services (constructor) but I would need to resolve them again.
Hope its clear enough to understand what I want to do
It is not clear from the question, because the code sample is incomplete. But probably, just probably, you need something like:
container.ClearCache(typeOf(IMyService));
container.RegisterInstance<IMyService>(
new MyService { ValueCPopulatedAfterLogin = "blah" },
ifAlreadyRegister: IfAlreadyRegister.Replace);