Skip to content

Commit

Permalink
ability to declare beans to be injected into grails by name of interface
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Oct 2, 2018
1 parent 3165af9 commit 36dbb31
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allprojects {
group 'com.agorapulse'
version micronautVersion
version "${micronautVersion}.1"

repositories {
jcenter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
beanDefinitionBuilder.addPropertyValue(MICRONAUT_BEAN_TYPE_PROPERTY_NAME, definition.getBeanType());
beanDefinitionBuilder.addPropertyValue(MICRONAUT_CONTEXT_PROPERTY_NAME, micronautContext);
beanDefinitionBuilder.addPropertyValue(MICRONAUT_SINGLETON_PROPERTY_NAME, definition.isSingleton());

String name = definition.getName();
if (name.equals(definition.getBeanType().getName())) {
if (!micronautBeanQualifierType.isAnnotation() && micronautBeanQualifierType.isInterface()) {
name = NameUtils.decapitalize(micronautBeanQualifierType.getSimpleName());
} else if (name.equals(definition.getBeanType().getName())) {
name = NameUtils.decapitalize(definition.getBeanType().getSimpleName());
}
((DefaultListableBeanFactory) beanFactory).registerBeanDefinition(name, beanDefinitionBuilder.getBeanDefinition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class GrailsMicronautBeanProcessorSpec extends Specification {
expect:
applicationContext.getBean('widget') instanceof Widget
applicationContext.getBean('prototypeBean') instanceof PrototypeBean
applicationContext.getBean('someInterface') instanceof SomeInterface
applicationContext.getBean('someInterface') instanceof SomeImplementation
when:
PrototypeBean prototypeBean = applicationContext.getBean(PrototypeBean)
then:
Expand Down Expand Up @@ -61,11 +63,16 @@ class GrailsConfig {

@Bean
GrailsMicronautBeanProcessor widgetProcessor() {
new GrailsMicronautBeanProcessor(Widget, Prototype)
new GrailsMicronautBeanProcessor(Widget, SomeInterface, Prototype)
}

}

interface SomeInterface { }

@Singleton
class SomeImplementation implements SomeInterface { }

@Singleton
class Widget {}

Expand Down

0 comments on commit 36dbb31

Please sign in to comment.