I want to set property in some injected service in controller for later abusing it when this service will be injected in other place during the same request, so I expect this property not to change as far as service is injected as Scoped.
Is that safe approach or how would you suggest to achive such a behaviour?
MyController(IServiceWithProperty serviceWithProperty) {
_serviceWithProperty = serviceWithProperty;
}
public IActionResult Get(int settingToSet) {
_serviceWithProperty.SetProperty(settingToSet);
return Ok(_anotherService.GetSomething());
}
And as I said AnotherService
injects ServiceWithProperty
as well.
public class AnotherService : IAnotherService {
public AnotherService(IServiceWithProperty serviceWithProperty) {
_serviceWithProperty = serviceWithProperty;
}
public string GetSomething() {
int prop = _serviceWithProperty.GetProperty(); //here I expect to get property which has been set in controller, would that work and is it fine to do it like that?
}
}