开发者

Service Layer which can switch between Web Service Layer and Data Access Layer

开发者 https://www.devze.com 2022-12-30 00:35 出处:网络
I am building an application that will function as a client-server application, and also as a disconnected client application.I will be using WPF (browser app for client-server application).

I am building an application that will function as a client-server application, and also as a disconnected client application. I will be using WPF (browser app for client-server application).

When interacting with the server's database, I will need to connect using WCF web services. When connecting with the localized database, I will need to connect using the local db's data access layer.

What methods/patterns ex开发者_如何学运维ist for this sort of architecture?

EDIT: I was able to create a common service layer for both data/wcf web services as Charles recommends below with the help of this SO post.


Please note that I do not, by any stretch, consider myself an expert on this matter. But I hope these musings are of some use. These are based on my own experience.

You could do this by having two implementations of your data access layer (DAL).

Define a single generic interface between your business layer and your DAL.

Create one implementation of the DAL which talks to the database.

Create one implementation of the DAL which talks to the web service.

Both of these will implement your generic interface such that the business layer (BL) need not know which DAL is currently being used. Obviously there is some special logic required to handle connections between the application and one of the DALs. This may reside in a special layer in between the DAL and the BL, or in a cross-cutting layer (e.g. the communications layer).

It might be more practical for you to gear your interface more towards one implementation or the other. If this is the case, you'll probably have to adapt the lesser-implementation to the interface. To do this while keeping the actual implementation of the lesser layer loosely coupled, you would use the adapter pattern.

Further considerations: maybe you would like your DAL implementations to be re-usable. Essentially they become APIs in their own right. In this case you'd design them to a relatively non-specific public interface. Now the DAL dictates its interface to the consumer (your application), instead of vice-versa.

Aside from that it's straight-forward layering and abstraction. Here is a downloadable Microsoft publication on application architecture (which I've just started reading): http://msdn.microsoft.com/en-us/library/ff650706.aspx


The pattern would be factory with strategy. You could do something like this - IDatabase with all methods defining for connect etc. DBWCF class for connecting to WCF service which inherits from Idatabase.dblocal for accessing local db also inherits from Idatabase. In the config file specify if local db needs to be connected or wcf. Have a config class which would read from config file and call necessary factory. the factory would instatiate either wcfdb or dblocal class. And everywhere use Idatabase.

0

精彩评论

暂无评论...
验证码 换一张
取 消