-
Notifications
You must be signed in to change notification settings - Fork 25
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 #752 from SentryMan/postConstructBeans
`PostConstruct` method Direct Injection
- Loading branch information
Showing
12 changed files
with
205 additions
and
21 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
blackbox-test-inject/src/main/java/org/example/myapp/config/LifeFour.java
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,18 @@ | ||
package org.example.myapp.config; | ||
|
||
import io.avaje.inject.PostConstruct; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
public class LifeFour { | ||
|
||
public String _state; | ||
|
||
@PostConstruct | ||
void post(@Named("foo") LifeOne one, LifeTwo two) { | ||
_state = "post|" | ||
+ (one != null ? "one|" : "") | ||
+ (two != null ? "two" : ""); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
blackbox-test-inject/src/main/java/org/example/myapp/config/LifeOne.java
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,17 @@ | ||
package org.example.myapp.config; | ||
|
||
import io.avaje.inject.BeanScope; | ||
import io.avaje.inject.PostConstruct; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
public class LifeOne { | ||
|
||
public String _state; | ||
|
||
@PostConstruct | ||
void post(BeanScope scope) { | ||
_state = "post|" | ||
+ (scope != null ? "scope" : ""); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
blackbox-test-inject/src/main/java/org/example/myapp/config/LifeProtoTwo.java
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,18 @@ | ||
package org.example.myapp.config; | ||
|
||
import io.avaje.inject.BeanScope; | ||
import io.avaje.inject.PostConstruct; | ||
import io.avaje.inject.Prototype; | ||
|
||
@Prototype | ||
public class LifeProtoTwo { | ||
|
||
public String _state; | ||
|
||
@PostConstruct | ||
void post(LifeOne one, BeanScope scope) { | ||
_state = "post|" | ||
+ (one != null ? "one|" : "") | ||
+ (scope != null ? "scope" : ""); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
blackbox-test-inject/src/main/java/org/example/myapp/config/LifeThree.java
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,16 @@ | ||
package org.example.myapp.config; | ||
|
||
import io.avaje.inject.PostConstruct; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
public class LifeThree { | ||
|
||
public String _state; | ||
|
||
@PostConstruct | ||
void post(LifeOne one) { | ||
_state = "post|" | ||
+ (one != null ? "one" : ""); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
blackbox-test-inject/src/main/java/org/example/myapp/config/LifeTwo.java
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,18 @@ | ||
package org.example.myapp.config; | ||
|
||
import io.avaje.inject.BeanScope; | ||
import io.avaje.inject.PostConstruct; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
public class LifeTwo { | ||
|
||
public String _state; | ||
|
||
@PostConstruct | ||
void post(LifeOne one, BeanScope scope) { | ||
_state = "post|" | ||
+ (one != null ? "one|" : "") | ||
+ (scope != null ? "scope" : ""); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
blackbox-test-inject/src/test/java/org/example/myapp/config/PostConstructParametersTest.java
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,27 @@ | ||
package org.example.myapp.config; | ||
|
||
import io.avaje.inject.BeanScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class PostConstructParametersTest { | ||
|
||
@Test | ||
void factorySecondaryAsProvider() { | ||
try (BeanScope testScope = BeanScope.builder().build()) { | ||
var one = testScope.get(LifeOne.class); | ||
var two = testScope.get(LifeTwo.class); | ||
var three = testScope.get(LifeThree.class); | ||
var four = testScope.get(LifeFour.class); | ||
var protoTwo = testScope.get(LifeProtoTwo.class); | ||
|
||
assertThat(one._state).isEqualTo("post|scope"); | ||
assertThat(two._state).isEqualTo("post|one|scope"); | ||
assertThat(three._state).isEqualTo("post|one"); | ||
assertThat(four._state).isEqualTo("post|one|two"); | ||
assertThat(protoTwo._state).isEqualTo("post|one|scope"); | ||
} | ||
} | ||
|
||
} |
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
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
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
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
18 changes: 18 additions & 0 deletions
18
inject-generator/src/test/java/io/avaje/inject/generator/models/valid/lifecycle/Minos.java
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,18 @@ | ||
package io.avaje.inject.generator.models.valid.lifecycle; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import io.avaje.inject.BeanScope; | ||
import io.avaje.inject.PostConstruct; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
public class Minos { | ||
|
||
@PostConstruct | ||
void prepareThyself(Serpent serpent, Consumer<String> c, BeanScope b) {} | ||
|
||
// @PreDestroy | ||
// void thyEndIsNow() { | ||
// } | ||
} |
15 changes: 15 additions & 0 deletions
15
inject-generator/src/test/java/io/avaje/inject/generator/models/valid/lifecycle/Serpent.java
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,15 @@ | ||
package io.avaje.inject.generator.models.valid.lifecycle; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import io.avaje.inject.BeanScope; | ||
import io.avaje.inject.PostConstruct; | ||
import io.avaje.inject.Prototype; | ||
|
||
@Prototype | ||
public class Serpent { | ||
|
||
@PostConstruct | ||
void hiss(Consumer<String> c, BeanScope b) {} | ||
|
||
} |