Is there an alternative to bastard injection? (AKA poor man’s injection via default constructor)

As far as I understand, this question relates to how to expose a loosely coupled API with some appropriate defaults. In this case, you may have a good Local Default, in which case the dependency can be regarded as optional. One way to deal with optional dependencies is to use Property Injection instead of Constructor Injection – in fact, this is sort of the poster scenario for Property Injection.

However, the real danger of Bastard Injection is when the default is a Foreign Default, because that would mean that the default constructor drags along an undesirable coupling to the assembly implementing the default. As I understand this question, however, the intended default would originate in the same assembly, in which case I don’t see any particular danger.

In any case you might also consider a Facade as described in one of my earlier answers: Dependency Inject (DI) “friendly” library

BTW, the terminology used here is based on the pattern language from my book.

Leave a Comment