且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WCF和Repository模式之间的区别

更新时间:2023-11-20 13:57:52

是否已从存储库模式创建wcf?

编号类/接口更像是面向对象的构造,在这种情况下是VB.Net或C#语言的东西,并且更常用。模式通常使用接口和类继承来工作,但不是专门用于存储库模式。



存储库模式可以概括为代理或外观psuedo-code中的数据访问层通常涉及包装CRUD操作:



Has wcf created from Repository pattern?
No. Classes/interfaces are more of a Object oriented construct, in this case a VB.Net or C# language thing and is in more general use. Often patterns make use of Interfaces and class inheritance to work, but not specifically to the repository pattern.

The repository pattern can be summed up as a proxy or facade around a data access layer in psuedo-code it would be typically involve wrappering CRUD operations:

public interface IRepository <T>
{
    public void Insert(T entity);
    public void Delete(T entity);
    //For reasons of usability, especially with LINQ the next to would return IQueryable<T>
    IEnumerable<T> GetAll();
    IEnumerable<T> Search(Expression<Func<T,bool>> predicate);
    T GetById(int id); //Assuming an int index..
    void Update(T updatedEntity)
}





使用LINQ你可能想要一个Save方法来提交更新,更新将是多余的,因为你可以做 GetById() - > [更新对象] - > Save()如果正确实现。

虽然WCF可能会暴露类似这些方法的东西(例如WCF数据服务 [ ^ ], REST WCF [ ^ ],甚至是手工制作的东西) - 这实际上是WCF的一个应用程序,而不是WCF是存储库模式的一个示例。



希望这有帮助。



With LINQ you'd probably want a Save method to commit updates, the Update would be redundant as you could then do a GetById() --> [update object] --> Save() if correctly implemented.
Though it is possible for WCF to expose something like these methods (e.g. WCF Data Services[^], REST WCF [^], or even something hand-rolled) - this is really one application of WCF, rather than WCF being an example of the repository pattern.

Hope this helps.