Disadvantages of JIT injection

While JIT injection can be handy, it cannot be used in all scenarios, and there are a few gotchas to be wary of. These include the following:

Can only be applied to static dependencies—The first and perhaps most significant disadvantage is that this method can only be applied to dependencies that only change during testing. We cannot use it to replace parameter injection or config injection. This is caused by the fact that dependency instantiation happens inside a private method and only on the first attempt to access the variable.

Dependency and user life cycles are not separated—When using constructor injection or parameter injection, it's often safe to assume the dependency being injected is fully initialized ...

Get Hands-On Dependency Injection in Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.