将域实体放入 (ASP.NET) Session,或者更好的某种 DTO?

发布于 2024-09-04 07:17:44 字数 347 浏览 1 评论 0原文

目前,我们将域对象/实体放入 ASP.NET 会话中。

现在我们考虑从 InProc 会话转移到状态服务器。这要求会话内的所有对象都是可序列化的。我们考虑创建自定义会话对象(DTO 会话对象?),而不是使用 [Serializable] 属性注释所有对象,它只包含我们需要的信息:

缺点:

  • 必须重新加载实体,这需要额外的数据库往返

优点:

  • 会话状态更小
  • 会话信息更具体(可能是 CON)
  • 没有不需要的域实体注释

您觉得怎么样?我们应该使用某种 DTO 来存储会话内部,还是应该坚持使用好的旧实体?

Currently we put domain objects/entities into our ASP.NET sessions.

Now we considering moving from InProc sessions to state server. This requires that all objects inside session are serializable. Instead to annotate all objects with the [Serializable] attribute, we thought about creating custom-session objects (DTO Session Objects?), which only contain the information we need:

CONS:

  • Entities must be reloaded, which requires additional DB round-trips

PROS:

  • Session State is smaller
  • Session information is more specific (could be a CON)
  • No unneeded annotation of Domain-Entities

What do you think? Should we use some kind of DTOs to store inside the session, or should we stick with good old entities?

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

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

发布评论

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

评论(1

因为看清所以看轻 2024-09-11 07:17:44

如果您正在考虑迁移到 ASP.NET MVC,这些 DTO 将成为您的模型视图数据对象,这可以方便地进行迁移。

是的,会话信息将更加具体,因为 DTO 将特定于其使用行为。它应该减少没有未使用的信息甚至受限信息的开销。

特定的 DTO 还将在其他方面提供帮助;如果您在表示层中实现其他技术,例如 Silverlight、Flash 等,并且需要在 Web 服务中使用相同的对象。

If you are thinking of moving to ASP.NET MVC, these DTO's become your Model ViewData Objects, which could make for a handy migration.

Yes, Session info wil lbe more specific as DTO's will be specific to the behaviour of it's usage. It should reduce the overhead in not having unused info or even restricted info.

Specifc DTO's will also help with other things; If you implement other technologies in your presentation layer, eg Silverlight, Flash etc and need the same objects in a webservice.

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