3939 */
4040public class AvajeInjectModule implements Extension {
4141
42- private final BeanScopeBuilder beanScope ;
42+ private final BeanScopeBuilder scopeBuilder ;
4343
4444 public static AvajeInjectModule of () {
4545 return new AvajeInjectModule (BeanScope .builder ());
@@ -49,8 +49,8 @@ public static AvajeInjectModule of(BeanScopeBuilder beanScope) {
4949 return new AvajeInjectModule (beanScope );
5050 }
5151
52- public AvajeInjectModule (@ NonNull BeanScopeBuilder beanScope ) {
53- this .beanScope = beanScope ;
52+ public AvajeInjectModule (@ NonNull BeanScopeBuilder scopeBuilder ) {
53+ this .scopeBuilder = scopeBuilder ;
5454 }
5555
5656 @ Override
@@ -60,7 +60,6 @@ public boolean lateinit() {
6060
6161 @ Override
6262 public void install (Jooby application ) {
63-
6463 application
6564 .getServices ()
6665 .entrySet ()
@@ -69,20 +68,20 @@ public void install(Jooby application) {
6968 var key = e .getKey ();
7069 var provider = e .getValue ();
7170 if (key .getName () == null ) {
72- beanScope .provideDefault (key .getType (), provider ::get );
71+ scopeBuilder .provideDefault (key .getType (), provider ::get );
7372 } else {
74- beanScope .bean (key .getName (), key .getType (), provider );
73+ scopeBuilder .bean (key .getName (), key .getType (), provider );
7574 }
7675 });
7776
7877 final var environment = application .getEnvironment ();
7978
80- beanScope .bean (Environment .class , environment );
81- beanScope .profiles (environment .getActiveNames ().toArray (String []::new ));
79+ scopeBuilder .bean (Environment .class , environment );
80+ scopeBuilder .profiles (environment .getActiveNames ().toArray (String []::new ));
8281
8382 // configuration properties
8483 final var config = environment .getConfig ();
85- beanScope .configPlugin (new JoobyPropertyPlugin (config ));
84+ scopeBuilder .configPlugin (new JoobyPropertyPlugin (config ));
8685
8786 for (var entry : config .entrySet ()) {
8887 String name = entry .getKey ();
@@ -91,9 +90,11 @@ public void install(Jooby application) {
9190 if (value instanceof List <?> values ) {
9291 value = values .stream ().map (Object ::toString ).collect (Collectors .joining ("," ));
9392 }
94- beanScope .bean (name , String .class , value .toString ());
93+ scopeBuilder .bean (name , String .class , value .toString ());
9594 }
9695
97- application .registry (new AvajeInjectRegistry (beanScope .build ()));
96+ var beanScope = scopeBuilder .build ();
97+ application .registry (new AvajeInjectRegistry (beanScope ));
98+ application .onStop (beanScope );
9899 }
99100}
0 commit comments