Thank you all. Sounds like we have consensus. I'll proceed to create a JIRA to track the task.
--Misagh ----- Original Message ----- > From: "Andrea Patricelli" <andreapatrice...@apache.org> > To: "dev" <dev@syncope.apache.org> > Sent: Monday, February 22, 2021 7:44:13 PM > Subject: Re: Proposal: using ctor-level dependency injection > Hi Misagh, > > definitely +1 also from me! > > Best regards, > Andrea > > 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? >> >> --Misagh >> >> [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 >> > -- > Andrea Patricelli > > Tirasa - Open Source Excellence > http://www.tirasa.net/ > > Member at The Apache Software Foundation > Syncope