DInject has moved to avaje.io/inject - taking you there now ...
Documentation / DInject
DInject Dependency Injection
DInject is designed to be a fast and light dependency injection library for server-side Java and Kotlin developers.
It uses source code generation (like Dagger). There is no use of reflection or classpath scanning.
It is orientated to server-side use by providing similar functionality to Spring DI including Lifecycle support, @Factory + @Bean, @Primary + @Secondary and the ability to get beans from the context.
Based on JSR-330
DInject is based on JSR-330: Dependency Injection for Java - javax.inject with some extensions similar to Spring DI.
Spring DI like extensions
@Factory + @Bean
DInject has @Factory + @Bean which work the same as Spring DI's @Configuration + @Bean and also Micronaut's @Factory + @Bean.
This provides a more convenient alternative to the JSR-330 javax.inject.Provider<T> interface and is also more natural for people who familiar with Spring DI or Micronaut DI.
@Primary @Secondary
DInject has @Primary @Secondary annotations which work the same as Spring DI's @Primary @Secondary and also Micronaut DI's @Primary @Secondary.
These provide injection precedence in the case of injecting an implementation when multiple injection candidates are available.
Spring DI translation
Spring | DInject | JSR-330 |
---|---|---|
@Component, @Service, @Controller, @Repository | @javax.inject.Singleton | Yes |
FactoryBean<T> | javax.inject.Provider<T> | Yes |
@Inject, @Autowired | @javax.inject.Inject | Yes |
@Autowired(required=false) | @javax.inject.Inject Optional<T> | Yes |
@PostConstruct | @javax.inject.PostConstruct | Yes |
@PreDestroy | @javax.inject.PreDestroy | Yes |
Non standard extensions to JSR-330 | ||
@Configuration @Bean | @Factory @Bean | No |
@Primary | @Primary | No |
@Secondary | @Secondary | No |
AOP
Using libraries that provide their own AOP/enhancement makes DInject simpler and lighter.
Currently DInject does not include AOP and the expectation is that AOP functionality comes
with other libraries. For example Ebean ORM has
@Transactional
and Metrics
libraries have their own @Timed
.
The following are library recommendations for @Transactional, @Value and @Timed.
Spring | Recommendation |
---|---|
@Transactional | Ebean @Transactional |
@Value | Avaje Config |
@Timed | Avaje Metrics |