为什么 WCF RIA 服务中的 DomainContext 不实现 IDisposable 模式?

发布于 2024-09-05 10:47:24 字数 163 浏览 3 评论 0原文

只是用 RIA 服务做了一些工作,我在 MSDN 文档中看到它或其层次结构上的任何父级都没有实现 IDisposable。我想知道这个设计决策是什么...由于 DomainContext 是一个有状态资源,所以在完成后使用 Dispose() 来释放它不是很好吗?

谢谢,

斯科特

Just doing some work with RIA services and I see in the MSDN documentation that neither it or any parents up its' hierarchy implement IDisposable. I'm wondering what the design decision was for this...as DomainContext is a stateful resource, wouldn't it be nice to have a Dispose() to release it when done ?

Thanks,

Scott

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙沙粒小 2024-09-12 10:47:24

有状态对象并不意味着需要 IDisposable。

真正的问题是您会在 Dispose 中做什么。

理论上你唯一能做的就是中止任何待处理的网络请求。但是,最好让应用程序开发人员调用正确的 Cancel 方法 - 因为 Load/Submit 都是显式调用,所以 Cancel 也应该如此。

IDisposable 的存在也会令人困惑 - 考虑到缺乏具体场景,何时需要调用它,何时不需要。

因此,DomainContext 上没有 IDisposable。

A stateful object doesn't imply IDisposable is required.

The real question is what would you do in Dispose.

At best the only thing you could theoretically do is abort any pending web requests. However, that is probably better left to the app developer to call the right Cancel method - since Load/Submit are all explicit calls, Cancel should be as well.

The existence of IDisposable would be confusing as well - when is it required to be called, and when not, given the lack of concrete scenarios.

Hence no IDisposable on DomainContext.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文