I have a situation where there are classes compiled outside the preview of the Micronaut's annotation processors. These classes have annotations on their methods that I want to use to apply a Micronaut MethodInterceptor to.
This causes issues because Micronaut has to be aware of the concrete class that contains these annotations, and when combined with the need to apply MethodInterceptor's to this class, it means Micronaut wants to extend the class, and so the class in question needed to be open to extending, or we need to move the annotations on to an interface and away from the concrete class, which causes issues with our hexagonal design/architecture approach.
What I propose is an optimization to how the InterceptedProxy is generated, from the metadata in the @Factory class.
If these conditions are met:
1) For a given @Factory function, if it has a @Bean annotation where typed is supplied with only interfaces
2) And the @Bean function returns a concrete type, implementing said interfaces
3) And you needed to apply some AOP to the bean, @Transactional or custom MethodInterceptors etc..
Then
1) Generate the ExecutableMethodsDefinition using the concrete return type of the @Bean function as usual.
2) BUT, generate the InterceptedProxy using the interfaces declared in the @Bean's typed list
ie. don't try and extend the concrete return type to generate a proxy, if we only need to expose the bean with a given set of interfaces.
If this improvement was implemented, then I wouldn't need to open up the concrete class and the aspects being applied wouldn't need ProxyTargetConstructorMode.ALLOW or for Micronaut to extend the bean class at all.
Feature description
Per the discord help post: https://discordapp.com/channels/1121511613250412714/1167301199255568394
I have a situation where there are classes compiled outside the preview of the Micronaut's annotation processors. These classes have annotations on their methods that I want to use to apply a Micronaut
MethodInterceptor
to.This causes issues because Micronaut has to be aware of the concrete class that contains these annotations, and when combined with the need to apply
MethodInterceptor
's to this class, it means Micronaut wants to extend the class, and so the class in question needed to beopen
to extending, or we need to move the annotations on to an interface and away from the concrete class, which causes issues with our hexagonal design/architecture approach.What I propose is an optimization to how the
InterceptedProxy
is generated, from the metadata in the@Factory
class.If these conditions are met: 1) For a given
@Factory
function, if it has a@Bean
annotation wheretyped
is supplied with only interfaces 2) And the@Bean
function returns a concrete type, implementing said interfaces 3) And you needed to apply some AOP to the bean,@Transactional
or customMethodInterceptor
s etc..Then 1) Generate the
ExecutableMethodsDefinition
using the concrete return type of the@Bean
function as usual. 2) BUT, generate theInterceptedProxy
using the interfaces declared in the@Bean
'styped
list ie. don't try and extend the concrete return type to generate a proxy, if we only need to expose the bean with a given set of interfaces.If this improvement was implemented, then I wouldn't need to
open
up the concrete class and the aspects being applied wouldn't needProxyTargetConstructorMode.ALLOW
or for Micronaut to extend the bean class at all.