Alex Rivera | Logout

Dependency injection with no framework

Asked 2009-02-20T13:44:23.397
9

I'm writing a mid-sized analysis program (5-10kloc) in MATLAB (not my decision), and I'm trying to use dependency injection to make my code more testable. I think I understand the basic object/constructor injection model, but I'm confused as to how this scales up the dependency graph.

For instance, if I have object A, which has-a object B, which has-a object C, and object C has a dependency that needs to be injected, do I need to pass it through the entire chain? Eventually, since this is a data analysis program, everything basically comes back to one AnalyzeData object/method, does this mean that that object has to have all the dependencies of the entire program injected?

Perhaps the answer is simply to use a ServiceFactory/ServiceProvider in this case, but I'd like to know if it's possible to scale many dependencies up to a large object graph without a framework.

Also, corrections on my thinking/wording/fundamentals are encouraged - I've basically been learning most of this through Google/HN/SO.

Edit
Report

1 Answer

2

Roll your own IoC container where you can just ask for your dependencies without needing to inject them, or use the static gateway pattern to get a singleton to create classes dynamically using a factory.

I found this video a really useful intro to these topics - http://www.dnrtv.com/default.aspx?showNum=126

answered 2009-02-20T14:00:19.723

Your Answer