Service layer that can switch between the web service layer and the data access layer

I am creating an application that will run as a client / server application as well as a disconnected client application. I will be using WPF (Browser Application for Client Server Application).

When interacting with the server database, I will need to connect using WCF Web Services. When connecting to a localized database, I will need to connect using the local db data access layer.

What methods / patterns are there for this type of architecture?

EDIT: I was able to create a generic service layer for the data / wcf webservices as Charles recommends below using a SO post .

+2


a source to share


2 answers


Please note that by no means do I consider myself an expert on this subject. But I hope these reflections are helpful. They are based on my own experience.

You can do this by having two data access layer (DAL) implementations.

Define one common interface between your business layer and your DAL.

Create one DAL implementation that talks to the database.

Create one DAL implementation that talks to the web service.



Both of them implement your common interface, so the business layer (BL) doesn't need to know which DAL is currently in use. Obviously, there is some special logic to handle connections between an application and one of the DALs. It can be in a special layer between the DAL and BL, or in a cross-layer (for example, a communication layer).

It may be more practical for you to pass your interface more towards one implementation or the other. If so, you will probably have to adapt the smaller implementation to the interface. To do this while keeping the actual implementation of the weak layer with the smaller layer, you must use the adapter pattern.

Further considerations: Perhaps you would like your DAL implementations to be reused. In essence, they themselves become APIs. In this case, you will create them for a relatively unspecified public interface. The DAL now dictates its interface to the consumer (your application) instead of the other way around.

In addition, it is a straightforward layering and abstraction. Here is the Microsoft downloadable publication on Application Architecture (which I just started reading): http://msdn.microsoft.com/en-us/library/ff650706.aspx

+4


a source


The template will be a factory with a strategy. You could do something like this - IDatabase with all methods defining the connection, etc. DBWCF class for connecting to a WCF service that inherits from Idatabase.dblocal for accessing a local database also inherits from Idatabase. In the config file, specify whether you want to include local db or wcf. Have a config class that will read from the config file and call the required factory. factory will install either wcfdb or dblocal class. And use Idatabase everywhere.



0


a source







All Articles