On 9/23/05, emre akbas <[EMAIL PROTECTED]> wrote:
>
> Yes, to me too, getting datasource and then connection and passing this
> connection object to the service layer does not seem to be a good pattern.
> I
> said, by storing the datasource and servletcontext statically in the
> service
> layer may make life easier.
> I want to know various opinions about this topic. Thanks.


One serious issue with storing the ServletContext instance in your service
layer is that you make that layer dependent on the servlet API -- making it
much more complicated to test, or to use that code in non-webapp scenarios.
Some alternatives to consider:

* Pass in references to the data source (or, more likely, just the
Connection that should be used for a particular transaction).

* Configure your data sources using the JNDI namespace supported
by your container, and let the service layer do its own JNDI lookups.

* Use a dependency injection framework like Spring to inject the
connection instances as it configures the service objects.

Craig McClanahan

Reply via email to