简体   繁体   中英

getting rid of wcf data service tight coupling

I have a WCF Data Service that exposes my database over HTTP.

I realized that in the future, if my database changes, the clients will need to be updated as well, meaning that I have tightly coupled my database with clients.

How do I keep the benefits of WCF Data Service (it can easily expose data over http without much effort) and still have low-coupling ?

I've never used WCF, so this answer may not apply to this technology. But can you not encapsulate all DB logic in a method or class that your clients interact with? You can then change the logic in the event of a new DB, within the method/class and as long as the public contract is the same, then you should not have to update the client code.

For example:

class Client
{

     DatabaseClass DC = new DatabaseClass();
     DC.PerformMethod(); //Blissfully unaware of the methods inner workings.

 }

class DatabaseClass
{

    public void PerformMethod()
    {
        //Encapsulate DB Logic here.  If you need to change it, you can just change it here and the client needs to know nothing of it
     }

 }

Any problem in computer science can be solved by adding a layer of indirection

-David Wheeler

You should wrap your service in a layer of abstraction—I believe this is called the service proxy pattern.

Then, all your clients would interact with the proxy, and if your service changes in the future, you just have to change the proxy—unless of course something fundamental changes in the way the service works, in which case you would have to change your client, naturally.

In addition to the level of abstraction mentioned in another comment - you should be using Repositories.

http://martinfowler.com/eaaCatalog/repository.html

If you're using Entity Framework to expose your DB through WCF Data Services, than the EF is your level of indirection. It allows you change your DB schema and still keep the same model (Which is what WCF Data Services exposes).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM