SOA architecture data access

我们两清 提交于 2020-01-03 14:55:48

问题


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 ?


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/1669192/soa-architecture-data-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!