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>();
- Start the app
- ValueA and B are populated ValueC IS NOT
- Login now valueC is populated
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
- I launch the app and IMyService is registed in the container
- The "MyService" implementation has been invoked. (I guess the fact that has been invoked is key here)
- Now any injected services have some values populated
- I logged on and I get additional values and I would like to replaces all services inside my container
- I apply the "IfAlreadyRegister" syntax you suggested and If I resolve it again all the new additional properties are there.
- But when I go the service again the already injected services have not changed!!
- However if I resolve it again they are there..
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