Mike Edwards wrote:
Ramkumar R wrote:
Hi All,
I came across this requirement, while working with Spring, but I believe this topic also holds good for Java implementations.

Spring supports Constructor Injection by allowing to inject properties and objects via the constructors. Not sure if Tuscany should support this feature? As SCA+Spring depends on Tuscany runtime for binding and dependency injections.

I believe currently Tuscany supports injection of service references through getter & setter methods.

This question arises because the biggest benefit of setter injection is that it allows for circular dependencies. Circular dependencies are actually pretty common. If you have a UserService that needs to get information about an employer from CompanyService and the CompanyService needs information about employees from UserService, right there you have a circular dependency. In general I find a lot of circular dependencies between service methods, but with complex object models it is possible to have circular dependencies elsewhere.

So considering the circular dependency issue, I believe it would be a bad idea to support the same in Tuscany.

Like to hear from the community for more insight on this topic and how we should go about it.

--
Thanks & Regards,
Ramkumar Ramalingam

Folks,

The SCA Java specification explicitly supports constructor based injection of both properties and references, so Tuscany should support this.

 From the OASIS SCA Java specification - sca-javacaa-1.1-spec-cd01.pdf
Lines 94-97:

2.1.4 @Reference
Accessing a service using reference injection is done by defining a field, a setter method parameter, or a constructor parameter typed by the service interface and annotated with an @Reference annotation

- note the explicit description of "constructor parameter"

This is made clear in the formal definition of the @Reference annotation in section 8.15 (line 1375).

The same applies to the @Property annotation (Section 8.14, line 1311).


Currently, the SCA Spring specification says nothing about constructor injection, but I have raised a number of issues against that specification to fix this and other problems.



Yours,  Mike.


There are some use cases that need constructor injection.  If an
implementation requires an injected reference or property to be set
once only and never changed, constructor injection is a convenient
way to ensure this.

I don't think there is any problem with constructor injection and
circular dependencies.  In the example given, CompanyService instances
would be injected with UserService proxies, and UserService instances
would be injected with CompanyService proxies.  This does not create
circularity, because CompanyService and UserService instances don't
refer to each other directly.

  Simon


Reply via email to