开发者

getting rid of wcf data service tight coupling

开发者 https://www.devze.com 2023-02-26 21:16 出处:网络
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 m

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 ?


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.


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
     }

 }


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).

0

精彩评论

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

关注公众号