Skip to content

Commit 525a3e2

Browse files
committed
Merge branch 'master' of github.com:avaje/avaje-inject
2 parents 9c3d005 + 82c57b4 commit 525a3e2

File tree

1 file changed

+72
-3
lines changed

1 file changed

+72
-3
lines changed

README.md

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,80 @@
33
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/avaje/avaje-inject/blob/master/LICENSE)
44
[![Maven Central : avaje-inject](https://maven-badges.herokuapp.com/maven-central/io.avaje/avaje-inject/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.avaje/avaje-inject)
55

6-
# [avaje-inject](https://avaje.io/inject)
6+
# [Avaje-Inject](https://avaje.io/inject)
77
APT based dependency injection for server side developers - https://avaje.io/inject
88

9-
### Example module use
9+
## Quick Start
10+
#### 1. Add avaje-inject as a dependency.
11+
```xml
12+
<dependency>
13+
<groupId>io.avaje</groupId>
14+
<artifactId>avaje-inject</artifactId>
15+
<version>${avaje.inject.version}</version>
16+
</dependency>
17+
```
18+
#### 2. Add avaje-inject-generator annotation processor as a dependency with provided scope.
19+
```xml
20+
<dependency>
21+
<groupId>io.avaje</groupId>
22+
<artifactId>avaje-inject-generator</artifactId>
23+
<version>${avaje.inject.version}</version>
24+
<scope>provided</scope>
25+
</dependency>
26+
```
27+
If there are other annotation processors and they are specified via `maven-compiler-plugin`, then we add avaje-inject-generator there instead.
28+
```xml
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-compiler-plugin</artifactId>
32+
<configuration>
33+
<annotationProcessorPaths> <!-- All annotation processors specified here -->
34+
<path>
35+
<groupId>io.avaje</groupId>
36+
<artifactId>avaje-inject-generator</artifactId>
37+
<version>${avaje.inject.version}</version>
38+
</path>
39+
<path>
40+
... other annotation processor ...
41+
</path>
42+
</annotationProcessorPaths>
43+
</configuration>
44+
</plugin>
45+
```
46+
#### 3. Create a Bean Class annotated with @Singleton
47+
```java
48+
@Singleton
49+
public class Example {
1050

51+
private DependencyClass d1;
52+
private DependencyClass2 d2;
53+
54+
// Dependencies must be annotated with singleton,
55+
// or else be provided from another class annotated with @Factory
56+
public Example(DependencyClass d1, DependencyClass2 d2) {
57+
this.d1 = d1;
58+
this.d2 = d2;
59+
}
60+
}
61+
```
62+
Example factory class:
63+
```java
64+
@Factory
65+
public class ExampleFactory {
66+
@Bean
67+
public DependencyClass2() {
68+
return new DependencyClass2();
69+
}
70+
}
71+
```
72+
73+
#### 4. Use BeanScope to wire and retrieve the beans and use however you wish.
74+
```java
75+
BeanScope beanScope = BeanScope.builder().build()
76+
Example ex = beanScope.get(Example.class);
77+
```
78+
79+
### Example module use
1180
```java
1281
module org.example {
1382

@@ -22,7 +91,7 @@ module org.example {
2291
- Uses Java annotation processing for dependency injection
2392
- Generates source code
2493
- Avoids any use of reflection or classpath scanning (so low overhead and fast startup)
25-
- A `Library only` (a DI library and that's it ~25k in size)
94+
- A `Library only` (a DI library and that's it. ~25k in size)
2695

2796

2897
## Differences to Dagger

0 commit comments

Comments
 (0)