Lets say I have a method which requires a static property and I want to create unit tests, so I wrap it in a wrapper class. Let's call the interface IFoo & concrete class Foo.
Now if my method is called from within an MVC view, how do you get the wrapper instance into that method?
Obviously, I can add an IFoo parameter to my controller constructor, an IFoo property to my view model, and an IFoo parameter to my method, then pass it down the chain; controller, view model, view, extension method. That doesn't seem acceptable me.
So is there a cleaner way to do this?
I assumed a DI Container was the way to go. To be honest, I haven't needed one up until now, and I naively assumed I would just add Ninject, bind concrete types to interfaces, and make the following call within my method.
var dt = kernel.Get<IFoo>();
I assumed this would help me to avoid the entire constructor parameter / property trail mentioned above. Now I knew I'd still need to get the kernel variable from somewhere, but I thought I remembered seeing something about invoking it with thread/session/request scope. I thought I could instantiate the same instance of the kernel regardless of where it was invoked, but when I looked into it I found out that is only for the object instances the kernel is invoking ... not the kernel itself.
So, Is there any way to get an instance of Foo into the method without passing it through a bunch of objects which do nothing but pass it?