Advantages of JIT injection

This method was designed to address some of the pain points of traditional DI. The advantages listed here are specific to this method and in contrast to other forms of dependency injection. Benefits specific to this method include the following.

Better User Experience (UX) due to fewer inputs—I know I have raised this point a lot, but code that is easier to understand is also easier to maintain and extend. When a function has fewer parameters, it's inherently easier to understand. Compare the constructor:

func NewGenerator(storage Storage, renderer Renderer, template io.Reader) *Generator {   return &Generator{      storage:  storage,      renderer: renderer,      template: template,   }}

With this one:

func NewGenerator(template ...

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.