0 Replies Latest reply on Nov 24, 2010 6:52 AM by Thomas Goettlich

    Denpendency Injection Service Override

    Thomas Goettlich Novice



      before I ask my question, here's a short description of what we try to do:


      We are building a platform for our projects that consists of multiple components.

      Each component contains entities, data access objects and business services.


      If we use those components in a project and need to extend the entities, we inherit from the base entity and the dao but not from the service.

      The daos are abstract generic services, i.e. they provide generic implementations but are not annotated with @Stateless.

      The services are neither generic nor abstract and thus might be extended but the logic must not be overridden.


      A short example to illustrate my description:


      The user component contains the following classes:



      UserEntity{ /*code here*/ }


      abstract class UserDAOBean<Entity extends UserEntity>


           doCrudStuff(Entity user) { ... }




      @Local (IUserService.class)

      class UserServiceBean


        doBusinessLogic(UserEntity user) { ... }




      The project needs to extend UserEntity and thus we have the following:



      ProjectUserEntity extends UserEntity { /*additional attributes*/ }



      ProjectUserDAOBean extends UserDAOBean<ProjectUserEntity>



      doCrudStuff(ProjectUserEntity user) { /*some extended or changed code here */ }



      This works so far.


      The problem are the business services.

      When I want to extend UserServiceBean, that's no problem. I then just add a ProjectUserServiceBean and call that where needed.


      However, when I need to override a method - e.g. doBusinessLogic - I need other services to use the overriding service instead of the base one.

      I can't change the calling services and thus have to rely on DI to return the correct service.

      The problem is, that the JBoss 4.2.3 implemantion (that's what we're using) returns any service that implements the IUserService interface (and declares it as its local interface).


      So I need UserServiceBean not to be returned by DI or not be registered in the EJB 3 container at all.



      Finally the question: Is that possible? If so, how?



      Thanks in advance.




      (Edit: the topic was wrong, the problem is DI)