Dependency injection and IoC are a particularly wonderful kind of magic – I’m really only just beginning to get to grips with using it in a practical sense (and resisting the urge to spend the next month or three just writing tests and refactoring code to be tested) but once you start it becomes addictive as you see the benefits.
I use Unity. Whether that’s the right solution doesn’t really bother me – I have it and it works and it does all the things I want…
So, a simple problem – I have a set of providers of that impement IThingyProvider, they in turn require a a ThingyProviderConfiguration or a descendant (since Thingies can have varying number of parameters depending on the nature of the Thingy). How then do I inject the right Configuration object into a given ThingyProvider ?
How about:
public MyThingyProvider([Dependency(“My”)] ThingyProviderConfiguration config)
{
this.Config = config;
}
Huge amounts of “it just works”
I found the answer on stackoverflow here so kudos (and an upvote if this is useful) to Chris Tavares
Comments