If one uses property injection how do you set properties on that type? For example
public class MyClass
{
public ITimer MyTimer {get;set;}
}
We can use DI to resolve ITimer but how/where do we define property values for ITimer, for example, if you want to set the Interval property where does this happen?
Thanks
Please clarify …what do you mean by ‘if you want to set the Interval property where does this happen?’ If you are looking for when to set properties for ITimer, I prefer using a method for better readability and maintenance:
I don’t believe this will stop someone from altering the interval or other properties on the Timer. I don’t know if that is your intent.
Update:
Depending on your ITimer interface, you could completely hide the Interval property which means that the interval could not be altered because of encapsulation. Exposing the interval property through encapsulation requires something like the following:
…exposes a way to set an interval value – e.g.:
If the interface did not define the property, there is no way to access the encapsulated timer properties outside of your controlled API (except maybe by reflection …)
Hope that helps.