Micronaut as Dependency Injection Provider

If you are already familiar with Micronaut, most probably you know it as a framework for developing microservices-based applications. Micronaut support JVM languages Groovy and Kotlin in addition to Java. One of the less known facts about Micronaut is that it can also be used as a dependency injection capability provider for any of your JVM applications.

In my observation, there are two patterns of evolution when it comes to frameworks (and they are not mutually exclusive).

First - The framework starts with the intention to solve s small specific problem, and over a period, it builds on top of the existing functionality to cover more use-cases.

Second - This has to do with the internal structure. Over a while, the framework gets more modular, and the individual components can be used independently. For example, GORM became an independent component evolved from Grails

It is interesting to note that right from the beginning, Micronaut comes with an independent module of dependency injection feature. I believe there are two main reasons for this.

First - One of the objectives of Micronaut is to offer reflection-free design/ code. Since most of the current dependency injection implementations are dominated by reflection, having an independent module helps to have the same component as the host for implementation of alternatives to reflection. Put in another way we already know that DI implementation can be a potential independent component.

Second - Micronaut had to support Groovy. While Groovy already has highly sophisticated mechanisms for compile-time code generation in the form of AST transformations, Java had to rely upon annotation processor APIs. Hence there had to be two implementations for compile-time code generation and an independent component with multiple implementations naturally here.

We will see an example in an upcoming post.

Show Comments