I'm using Microsoft.Practices.ObjectBuilder in a web project to handle dependency injection (between view and presenter for example).
I've recently added an ASP.NET Web Service (.asmx) to handle ajax calls. I would like to use dependency injection with ObjectBuilder here as well, but I can't get it working.
I tried to just simply add something like this:
[CreateNew]
public MyClass MyClass
{
set
{
_myClass = value;
}
}
But this isn't working. The property setter of MyClass is never called. Is it even possible to get this working?
Regarding to old legacy system, especially for those using static - stateless classes, I found this design to be the most fit:
With this, I can still do dependency injection in unit test, using setter injection.
While, at the very point, does not change the existing code too much. And later when the times come, it can be modified using constructor DI.
It will also help your legacy colleague whom does not understand DI too much, to able to track the code faster (using
Go to Definition). And it can survive even withoutinterface/classdocumentation.