我在互联网上找到了一篇文章,介绍了如何实现仓储模式。实现方式与这里类似:
class ProductRepository : IProductRepository
{
var context;
public ProductRepository() {
this.context = new MyDataBaseDataContext();
}
// the rest of methods
}
但我不确定这是否正确,上下文发生了什么?垃圾回收器会处理此对象吗?还是最好使用using (...) { }语句创建上下文?