引用通用、可更新程序集的 ASP.NET 网站

发布于 2024-08-14 16:11:30 字数 908 浏览 1 评论 0原文

我正在开发一个由 .NET 网站上的许多 Web 应用程序使用的组件 (HttpModule),并且我希望该组件易于维护。我提出了下面概述的内容,但想看看是否有任何积极/消极的想法或对实现的一般反馈,因为我不是 100% 熟悉程序集加载,特别是在内存开销方面。

(我真的不想这样做:创建您自己的 .NET 程序集缓存)

轻量级 HttpModule 本身位于 GAC 中,并从站点的根 web.config 引用。对于每个请求,它都会打开一个文本文件(存储在网络的根/bin中),其中仅包含强命名的程序集名称(例如“My.MyLibrary,Version = 1.1.0.0,Culture = en,PublicKeyToken = 03689116d3a4ae33”),然后检查当前的 AppDomain 以查看它是否已被引用(迭代 GetAssemblies())。如果没有,则调用 Assembly.Load 来加载 myLibrary 并使用基本 Reflection 来 Invoke() My.MyLibrary 中的自定义方法,该方法实际上执行 HttpModule 的预期处理工作。

My.MyLibrary 本身也在 GAC 中。要升级应用程序而不重新启动任何应用程序,请将新版本放入 GAC 中,然后只需编辑文本文件中的字符串即可。我使用文本文件是因为 a) 它速度很快,b) 我不想更新 machine/web.config 并导致回收重定向 HttpModule 以使用新版本的 My.MyLibrary。似乎工作正常。当旧版本最终准备就绪时,可以从 GAC 中卸载它。因此,希望唯一需要重置应用程序池/iis 的时间是更改 HttpModule 部分。

任何回复都非常感谢!

-将要

I'm developing a component (HttpModule) that's used by a number of web applications on a .NET website, and I want the component to be easily maintainable. I've come up with something outlined below but wanted to see if there were any positive/negative thoughts or general feedback on the implementation, as I'm not 100% familiar with Assembly loading, especially in terms of memory overhead.

(I don't really want to do this: Create Your Own .NET Assembly Cache)

The lightweight HttpModule itself is in the GAC and referenced from the site's root web.config. On each request it opens a text file (stored in the web's root/bin) that contains just a strong named's assembly name (e.g. "My.MyLibrary, Version=1.1.0.0, Culture=en, PublicKeyToken=03689116d3a4ae33") and then checks the current AppDomain to see if it is already referenced (iterates over GetAssemblies()). If not, it then calls Assembly.Load to load myLibrary and uses basic Reflection to Invoke() a custom method in My.MyLibrary that actually does the intended processing work of the HttpModule.

My.MyLibrary itself is also in the GAC. To upgrade the app without any app restarts, put a new version in the GAC, and just edit the string in the text file. I'm using the text file because a) it's fast and b) I didn't want to have to update a machine/web.config and cause a recycle to redirect the HttpModule to use a new version of My.MyLibrary. It seems to work okay. The old version can be uninstalled from the GAC when it's finally ready to be. So hopefully the only time an app pool/iis reset would be needed would be to change the HttpModule part.

Any replies much appreciated!

-Will

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

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

发布评论

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

评论(1

世态炎凉 2024-08-21 16:11:30

就我个人而言,我想说,如果您可以避免使用任何后期绑定,那就更好了,但由于您希望能够自由地在应用程序中抛出新的程序集,那么后期绑定似乎确实有意义。

关于存储和检索程序集列表的方法,我将使用 XML 对象并从文件加载它。您会发现通过这种方式向其中添加额外信息更简单,否则您将不得不维护自己的文件格式。

您可能还需要考虑添加一些代码来捕获这些程序集生成的错误,卸载它们并在文件中放置一个标志,告诉 HttpModule 在更新之前不要加载它。

Personally I would say if you can avoid using any late binding it would be better, but as you want to be able to have the freedom to just throw a new assembly at your application then it does seem like late binding makes sense.

With regards to your method of storing and retrieving the list of assemblies, I would use an XML object and load it from the file. You will find adding extra information to it simpler this way, otherwise you will have to maintain your own file format.

You may also want to consider adding some code to catch errors generated from these assemblies, unload them and put a flag in your file telling your HttpModule not to load it until it has been updated.

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