Kijana Woodard

Software Minimalism


Constructor Injection is Partial Application

Wednesday, October 16, 2013

Looking back on my posts about violating ISP and duck typing, a question emerges: why not declare our dependencies on the methods that need them, rather than at the object level?

For example:

void LoginUser(IAuthenication auth, string userid)

This code would be very explicit and allow us to be more granular with our dependency chain.

However, it would also be a pain in the neck. Specifically, every caller would have to take a dependency on the target's dependencies just to pass them through.

Constructor Injection comes along to save the day. Our dependency arrives with it's dependencies already baked in.

In functional languages, dependencies can be "baked in" via partial application.

Constructor injection is partial application for OO.



If you see a mistake in the post *or* you want to make a comment, please submit an edit.

You can also contact me and I'll post the comment.

0 Comments...