Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ut-core into 1.1.x
  • Loading branch information
jameskleeh committed May 24, 2019
2 parents bf4fdcd + 6ff11a1 commit 345362a
Show file tree
Hide file tree
Showing 50 changed files with 601 additions and 401 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

25 changes: 0 additions & 25 deletions inject-java/src/test/java/io/micronaut/docs/replaces/TextBook.java

This file was deleted.

This file was deleted.

32 changes: 0 additions & 32 deletions inject-java/src/test/java/io/micronaut/docs/requires/Book.java

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions src/main/docs/guide/ioc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ try (ApplicationContext context = ApplicationContext.run()) { // <1>
// do something with your bean
}
----
// TODO should this be converted? The commentary is calling out a specific language's feature

<1> Run the api:context.ApplicationContext[]
<2> Retrieve a bean that has been dependency injected
Expand Down
17 changes: 4 additions & 13 deletions src/main/docs/guide/ioc/conditionalBeans.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,27 @@ The link:{api}/io/micronaut/context/annotation/Requires.html[Requires] annotatio

Consider the following example:

.Using @Requires
[source,java]
----
include::{testsjava}/requires/JdbcBookService.java[tags=requires, indent=0]
}
----
snippet::io.micronaut.docs.requires.JdbcBookService[tags="requires",indent=0, title="Using @Requires"]

The above bean defines two requirements. The first indicates that a `DataSource` bean must be present for the bean to load. The second requirement ensures that the `datasource.url` property is set before loading the `JdbcBookService` bean.

NOTE: Kotlin currently does not support repeatable annotations. Use the `@Requirements` annotation when multiple requires are needed. For example, `@Requirements(Requires(...), Requires(...))`. See https://youtrack.jetbrains.com/issue/KT-12794 to track this feature.

If you have multiple requirements that you find you may need to repeat on multiple beans then you can define a meta-annotation with the requirements:


.Using a @Requires meta-annotation
[source,java]
----
include::{testsjava}/requires/RequiresJdbc.java[tags=annotation, indent=0]
----
snippet::io.micronaut.docs.requires.RequiresJdbc[tags="annotation",indent=0, title="Creating a @RequiresJdbc meta-annotation"]

In the above example an annotation called `RequiresJdbc` is defined that can then be used on the `JdbcBookService` instead:

.Using a @Requires meta-annotation
.Using a meta-annotation
[source,java]
----
@RequiresJdbc
public class JdbcBookService implements BookService {
...
}
----
// TODO any way to make this multi-lang also?

If you have multiple beans that need to fulfill a given requirement before loading then you may want to consider a bean configuration group, as explained in the next section.

Expand Down
Loading

0 comments on commit 345362a

Please sign in to comment.