-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3198 from SentryMan/patch-1
Add Avaje-Inject to DI docs
- Loading branch information
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
== Dependency Injection | ||
|
||
include::di-avaje.adoc[] | ||
|
||
include::di-dagger.adoc[] | ||
|
||
include::modules/guice.adoc[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
=== Avaje Inject | ||
|
||
1) Add Avaje Inject to your project | ||
|
||
[dependency, groupId="io.avaje", artifactId="avaje-inject", version="9.8"] | ||
. | ||
|
||
2) Configure annotation processor | ||
|
||
.Maven | ||
[source, xml, role = "primary"] | ||
---- | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>...</version> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-inject-generator</artifactId> | ||
<version>9.8</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
---- | ||
|
||
.Gradle | ||
[source, kotlin, role = "secondary"] | ||
---- | ||
plugins { | ||
id "org.jetbrains.kotlin.kapt" version "1.9.10" | ||
} | ||
dependencies { | ||
kapt 'io.avaje:avaje-inject-generator:9.8' | ||
} | ||
---- | ||
|
||
3) Bootstrap Avaje from application: | ||
|
||
.Java | ||
[source, java, role = "primary"] | ||
---- | ||
import static io.jooby.Jooby.runApp; | ||
public class App extends Jooby { | ||
{ | ||
/** Avaje: */ | ||
BeanScope beanScope = BeanScope.builder() <1> | ||
.build(); | ||
MyService service = beanScope.get(MyService.class); <2> | ||
get("/", ctx -> { | ||
return service.doSomething(); | ||
}); | ||
} | ||
public static void main(String[] args) { | ||
runApp(args, App::new); | ||
} | ||
} | ||
---- | ||
|
||
.Kotlin | ||
[source, kotlin, role = "secondary"] | ||
---- | ||
import io.jooby.kt.runApp | ||
fun main(args: Array<String>) { | ||
runApp(args) { | ||
val beanScope = BeanScope.builder() <1> | ||
.build() | ||
val service = beanScope.getMyService() <2> | ||
get("/") { | ||
service.doSomething() | ||
} | ||
} | ||
} | ||
---- | ||
|
||
<1> Bootstrap avaje inject bean container | ||
<2> Use Avaje provided objects | ||
|
||
==== MVC routes | ||
|
||
Integration of MVC routes with Avaje is as simple as: | ||
|
||
.MVC and Avaje | ||
[source, java, role = "primary"] | ||
---- | ||
import static io.jooby.Jooby.runApp; | ||
public class App extends Jooby { | ||
{ | ||
/** Avaje: */ | ||
BeanScope beanScope = BeanScope.builder() <1> | ||
.build(); | ||
mvc(beanScope.get(MyController.class)); <2> | ||
} | ||
public static void main(String[] args) { | ||
runApp(args, App::new); | ||
} | ||
} | ||
---- | ||
|
||
.Kotlin | ||
[source, kotlin, role = "secondary"] | ||
---- | ||
import io.jooby.kt.runApp | ||
fun main(args: Array<String>) { | ||
runApp(args) { | ||
val beanScope = BeanScope.builder() <1> | ||
.build() | ||
mvc(beanScope.get(MyController.class)) <2> | ||
} | ||
} | ||
---- | ||
|
||
<1> Bootstrap Avaje bean container | ||
<2> Register MVC route provided by Avaje |