-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Map of beans should always use bean definition to extract the name (#…
- Loading branch information
Showing
8 changed files
with
127 additions
and
10 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
inject-java/src/test/groovy/io/micronaut/inject/foreach/mapof/DefaultMyService.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,10 @@ | ||
package io.micronaut.inject.foreach.mapof; | ||
|
||
import io.micronaut.context.annotation.Requires; | ||
import jakarta.inject.Singleton; | ||
|
||
@Requires(property = "spec.name", value = "MapOfNameSpec") | ||
@Singleton | ||
public class DefaultMyService implements MyService { | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
inject-java/src/test/groovy/io/micronaut/inject/foreach/mapof/MainService.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 io.micronaut.inject.foreach.mapof; | ||
|
||
import io.micronaut.context.annotation.Requires; | ||
import jakarta.inject.Singleton; | ||
|
||
@Requires(property = "spec.name", value = "MapOfNameSpec") | ||
@Singleton | ||
public class MainService { | ||
|
||
private final MyFooService myFooService; | ||
private final MyServiceConsumer myServiceConsumer; | ||
|
||
public MainService(MyFooService myFooService, MyServiceConsumer myServiceConsumer) { | ||
this.myFooService = myFooService; | ||
this.myServiceConsumer = myServiceConsumer; | ||
} | ||
|
||
public MyFooService getMyFooService() { | ||
return myFooService; | ||
} | ||
|
||
public MyServiceConsumer getMyServiceConsumer() { | ||
return myServiceConsumer; | ||
} | ||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
inject-java/src/test/groovy/io/micronaut/inject/foreach/mapof/MyBarService.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,11 @@ | ||
package io.micronaut.inject.foreach.mapof; | ||
|
||
import io.micronaut.context.annotation.Requires; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
|
||
@Requires(property = "spec.name", value = "MapOfNameSpec") | ||
@Named("bar") | ||
@Singleton | ||
public class MyBarService implements MyService { | ||
} |
13 changes: 13 additions & 0 deletions
13
inject-java/src/test/groovy/io/micronaut/inject/foreach/mapof/MyFooService.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,13 @@ | ||
package io.micronaut.inject.foreach.mapof; | ||
|
||
import groovy.transform.CompileStatic; | ||
import io.micronaut.context.annotation.Requires; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
|
||
@Requires(property = "spec.name", value = "MapOfNameSpec") | ||
@Named("foo") | ||
@Singleton | ||
@CompileStatic | ||
public class MyFooService implements MyService { | ||
} |
3 changes: 3 additions & 0 deletions
3
inject-java/src/test/groovy/io/micronaut/inject/foreach/mapof/MyService.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,3 @@ | ||
package io.micronaut.inject.foreach.mapof; | ||
|
||
public interface MyService { } |
21 changes: 21 additions & 0 deletions
21
inject-java/src/test/groovy/io/micronaut/inject/foreach/mapof/MyServiceConsumer.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,21 @@ | ||
package io.micronaut.inject.foreach.mapof; | ||
|
||
import io.micronaut.context.annotation.Requires; | ||
import jakarta.inject.Singleton; | ||
|
||
import java.util.Map; | ||
|
||
@Requires(property = "spec.name", value = "MapOfNameSpec") | ||
@Singleton | ||
public class MyServiceConsumer { | ||
|
||
private final Map<String, MyService> myServices; | ||
|
||
public MyServiceConsumer(Map<String, MyService> myServices) { | ||
this.myServices = myServices; | ||
} | ||
|
||
public Map<String, MyService> getMyServices() { | ||
return myServices; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
inject-java/src/test/groovy/io/micronaut/inject/foreach/mapof/MyServiceConsumerSpec.groovy
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,31 @@ | ||
package io.micronaut.inject.foreach.mapof | ||
|
||
import io.micronaut.context.ApplicationContext | ||
import spock.lang.Specification | ||
|
||
class MapOfNameSpec extends Specification { | ||
|
||
void "test proper name resolution"() { | ||
given: | ||
def context = ApplicationContext.run( | ||
["spec.name": "MapOfNameSpec"] | ||
) | ||
MainService service = context.getBean(MainService) | ||
MyBarService barService = context.getBean(MyBarService) | ||
MyFooService fooService = context.getBean(MyFooService) | ||
DefaultMyService defaultMyService = context.getBean(DefaultMyService) | ||
when: | ||
def services = service.getMyServiceConsumer().getMyServices() | ||
|
||
then: | ||
services == Map.of( | ||
"bar", barService, | ||
"foo", fooService, | ||
"defaultMyService", defaultMyService | ||
) | ||
|
||
cleanup: | ||
context.close() | ||
} | ||
|
||
} |
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