views:

206

answers:

4

In my SOA architecture, I have several WCF services.
All of my services need to access the database.

Should I create a specialized WCF service in charge of all the database access ?
Or is it ok if each of my services have their own database access ?

In one version, I have just one Entity layer instanced in one service, and all the other services depend on this service.
In the other one the Entity layer is duplicated in each of my services.

The main drawback of the first version is the coupling induced.
The drawback of the other version is the layer duplication, and maybe SOA bad practice ?

So, what do so think good people of Stack Overflow ?

+2  A: 

Just my personal opinion, if you create a service for all database access then multiple services depend on ONE service which sort of defeats the point of SOA (i.e. Services are autonomous), as you have articulated. When you talk of layer duplication, if each service has its own data to deal with, is it really duplication. I realize that you probably have the same means of interacting with your relational databases or back from the OOA days you had a common class library that encapsulated data access for you. This is one of those things I struggle with myself, but I see no problem in each service having its own data layer. In fact, in Michele Bustamante's book (Chapter 1 - Page 8) - she actually depicts this and adds "Services encapsulate business components and data access". If you notice each service has a separate DALC layer. This is a good question.

RandomNoob
I was going along the same lines, except that he has one part of his DAO layer that all the WCF services depend on sharing, so having a separate database for each doesn't appear to work, until he fixes his database code.
James Black
The issue is that I have trouble splitting the database in bits. Some tables in that db are needed by all the WCF services. For example, I have one service that is in charge of raising alerts from vehicule gps positions. So I have tables describing the alerts, but also table that associate alerts and vehicules, and of course a Vehicule table. I have another service which is responsible for the parsing of the gps position, then it needs the table Vehicule and a GpsPosition table. In fact I have "core" tables like Vehicule, Users, fleet, needed by all services. Dunno how to split...
Roubachof
+2  A: 

Why not just use a dependency injection framework, and, if they are currently using the same database, then just allow them to share the same code, and if these were in the same project then they would all use the same dll.

That way, later, if you need to put in some code that you don't want the others to share, you can make changes and just create a new DAO layer.

If there is a certain singleton that all will use, then you can just inject that in when you inject in the dao layer.

But, this will require that they use the same DI framework controller.

James Black
+2  A: 

It sounds as if you have several services but a single database.

If this is correct you do not really have a pure SOA architecture since the services are not independant. (There is nothing wrong with not having a pure SOA architecture, it can often be the correct choice)

Adding an extra WCF layer would just complicate and slow down your solution.

I would recommend that you create a single data access dll which contains all data access and is referenced by each WCF service. That way you do not have any duplication of code. Since you have a single database, any change in the database/datalayer would require a redeployment of all services in any case.

Shiraz Bhaiji
+1  A: 

The real win that SOA brings is that it reduces the number of linkages between applications.

In the past I've worked with organizations who have done it a many different ways. Some data layers are integrated, and some are abstracted.

The way I've seen it most successfully done is when you create generic data-layer services for each app/database and you create the higher level services based on your newly created data layer.

Nathan