On 19/02/21 11:41, Misagh Moayyed wrote:
> Hello all,
>
> I want to discuss and propose a design change in the way Syncope components, 
> specially *Logic classes are constructed. For a concrete example, this 
> component [1] might be a good baseline.
>
> Components such as [1] do two things that seem less than ideal:
>
> 1) The class is directly annotated with a @Component
> 2) It uses field-injections by annotating fields with @Autowire and such
>
> I submit that this approach generally proves challenging, specially when it 
> comes to constructing a context for integration tests and dealing with 
> classpath scanning. There is lot of literature on why this (field injections) 
> might not be an ideal approach; The "test context and component scanning" is 
> one practical example that I myself ran into; Purists might also argue that 
> business-level components and logic classes should not be tied to the upper 
> framework per se (though I don't actually find myself in this camp all too 
> often!). 
>
> A better alternative perhaps would be:
>
> - Avoid field-injections and use ctor-level injections (this is the general 
> recommendation from Spring)
> - Do not use autowire/component/etc directly in business-level classes
> - ...which means do not rely as much (if ever) on classpath/context scanning
> - ...and instead, create and instantiate the bean directory in @Configuration 
> classes, conditionally and with direct control
> - ...or use a middle-ground for now, with something like this [2]
>
> The work feels largely cosmetic perhaps; I think it will pay off in the 
> future specially if it's something that is advocated by Spring and family.
>
> WDYT?

Hi Misagh,
thanks for bringing up this discussion.

Moving (especially, but not only) Logic classes from the current "@Component + 
@Autowired" setup to something more in line with [2] would be beneficial not 
only for cosmetics but also to simplify override or extensions for deployments.

At least for Logic, I suspect [3] would be the central place at least for 
IdRepo, then we'll need to setup similar classes form IdM and AM, respectively.

Globally, I'd say not a difficult but labor intensive task to accomplish.
A big +1 from my side.

Regards.

> [1] 
> https://github.com/apache/syncope/blob/master/core/am/logic/src/main/java/org/apache/syncope/core/logic/OIDCJWKSLogic.java
> [2] 
> https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/using-boot-spring-beans-and-dependency-injection.html
[3] 
https://github.com/apache/syncope/blob/master/core/idrepo/logic/src/main/java/org/apache/syncope/core/logic/LogicContext.java

-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Member at The Apache Software Foundation
Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
http://home.apache.org/~ilgrosso/

Reply via email to