views:

62

answers:

1

I have a three layered Java application consisting of a presentation layer, a business layer, and a data access layer. In my application, the business layer contains what I am calling service classes and my data access layer contains what I'm calling data access classes. I am using Spring for dependency injection and to manage database transactions from the business layer down.

I have been wondering lately if it is a "normal" practice to inject service classes into other service classes. The reason I am asking is that I have a service class that contains logic that I would like to use in other service classes and I do not want to duplicate the logic only to avoid injecting a service class into another service class. I'm worried about circular references between the service classes. To avoid doing this, I was going to create a facade to wrap up the logic that I need, but I figured I'd ask the community first.

A: 

How are your services connected to (obtained from) presentation layer? Are you injecting them as well or are you using some sort of service locator pattern?

I would normally go with the latter for both presentation layer and service layer, e.g. service1 that needs to call service2 would obtain it via service locator.

ChssPly76
The DAOs are injected into the service layer and the service classes are injected into the presentation layer. I don't have a service locator. I will look into that.
hoffmandirt