序列化 NHibernate 配置对象 - 检测过期还是按需重建?

发布于 2024-08-25 14:26:48 字数 990 浏览 2 评论 0原文

我一直在使用 序列化nhibernate 配置对象(还讨论了此处此处)将我的应用程序启动速度从大约 8 秒缩短到 1 秒。我也用的是flutter-nhibernate,所以路径更像是

  1. 代码中的ClassMap类定义
  2. fluidconfiguration
  3. xml
  4. nhibernate配置
  5. 配置序列化到磁盘。

这样做的问题是,人们会面临映射过时的风险 - 如果我更改映射但忘记重建序列化配置,那么我最终会在没有意识到的情况下使用旧映射。这并不总是会在测试过程中导致立即且明显的错误,并且多次发现和修复错误行为确实很痛苦。

有谁知道我如何能够检测我的类映射是否已更改,以便我可以立即发出警告/错误或根据需要重建它?

目前,我正在将已编译程序集的时间戳与序列化配置进行比较。这将拾取映射更改,但不幸的是,它会产生大量误报率,因为对代码的任何更改都会导致过期标志。我无法将类映射移动到另一个程序集,因为它们紧密集成到业务逻辑中。

这已经困扰我一段时间了,所以我想知道是否有人有任何建议?

I've been using serialized nhibernate configuration objects (also discussed here and here) to speed up my application startup from about 8s to 1s. I also use fluent-nhibernate, so the path is more like

  1. ClassMap class definitions in code
  2. fluentconfiguration
  3. xml
  4. nhibernate configuration
  5. configuration serialized to disk.

The problem from doing this is that one runs the risk of out of date mappings - if I change the mappings but forget to rebuild the serialized configuration, then I end up using the old mappings without realising it. This does not always result in an immediate and obvious error during testing, and several times the misbehaviour has been a real pain to detect and fix.

Does anybody have any idea how I would be able to detect if my classmaps have changed, so that I could either issue an immediate warning/error or rebuild it on demand?

At the moment I am comparing timestamps on my compiled assembly against the serialized configuration. This will pickup mapping changes, but unfortunately it generates a massive false positive rate as ANY change to the code results in an out of date flag. I can't move the classmaps to another assembly as they are tightly integrated into the business logic.

This has been niggling me for a while so I was wondering if anybody had any suggestions?

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

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

发布评论

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

评论(1

泪是无色的血 2024-09-01 14:26:48

为什么不直接创建序列化配置文件作为构建过程的一部分并将其包含在部署包中?

它仍然是序列化的以便快速加载,但保证您每个版本都有最新版本。

Why not just create the serialized configuration file as part of your build process and include it in your deployment package?

It's still serialized for quick-loading but you're guaranteed to have the latest version for every build.

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