0 Replies Latest reply on Jun 16, 2009 6:24 PM by Brendan Farragher

    Thoughts about annotated EntityManager and coupling-broken encapsulation

    Brendan Farragher Newbie

      I just finished writing my first Seam application, and I would like to know how the community approaches or thinks about certain design implications regarding coupling to injected Seam components.

      I would like to know what you think/how you handle the coupling that establishes itself when certain Seam components are annotated, as opposed to retrieving the components from a factory class that might be provided by Seam (as Spring would do... I know that component configuration is possible with Seam, but this seems to defeat Seam's original intention to inject with annotations).

      The most prominent examples are with an injected EntityManager or Log instance. If I inject EntityManager into one of my Seam components (one that has the @Name annotation), then delegate persistence or logging operations to a secondary class, I have to pass EntityManager to that class in order for the class to perform DB persistence operations (this differs from Spring-Hibernate where you can just grab a session from a session factory at any point i.e, underneath the covers, and ENCAPSULATE the access to a session or session factory). With Seam, there seems to be an undesired coupling that arises by the framework between the API of a target class like the one described, and the injected EntityManager.

      My alternative thought on this was to possibly inject the EntityManager into a single Seam component, and then pass the Seam component around as a service object. But this seems to have potential drawbacks as they pertain component scope, long-running conversations, and-or annotating the EntityManager with @PersistenceContext (type equals ENTENDED).

      The EntityManager and Log componenets are instances where I feel it would be desirable to be able to retrieve them programmatically, underneath the covers, rather than having to annotate, and then pass the components as arguments to method calls or constructors. The annotated components seem to create a coupling to the Seam framework itself in this regard.

      Do you think this is a downside to using annotated components for dependency injection?

      I also tend to think that it is a negative with Seam annotated components (such as EntityManager and Log) that they are received from the framework at a global instance scope (i.e - this breaks encapsulation for the class).

      These are just some observations of mine after completing an initial seam project, and I would just like to know what other people think about these issues.