为什么 WCF RIA 服务中的 DomainContext 不实现 IDisposable 模式?
只是用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有状态对象并不意味着需要 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.