ASP.NET中的类库和静态变量
我有应该封装 orm 逻辑的类库。为了避免一些数据库调用,它应该包含某种缓存或静态变量(我想避免它们)。它用于 asp.net 和 wcf 应用程序。由于它是类库,我不想访问缓存或其他与 ASP.NET 相关的东西。我还想避免静态变量,因为它们的应用程序范围性质。
我应该如何实施?为了实现这个目标你会做什么?
编辑:
为了简化:想象一下封装 DAL 的类库。它与数据库对话。里面有一些昂贵的查询。其中一些应该为每个用户获取一次并存储在某个地方,其中一些可以为每个应用程序使用(也存储以避免将来调用数据库)。问题是,通常我会使用 Cache,但由于它是 DAL 类库,我想在其中包含此功能(而不是在 asp.net 中)。希望现在更清楚了;)
I have class library which should encapsulates orm logic. To avoid some db calls, it should contain some kind of cache or static variables (I want to avoid them). It's used in asp.net and wcf applications. Since it's class library, I don't want to access Cache or other asp.net related stuff. I also want to avoid static vars because of the application scope nature of them.
How should I implement that? What do you do to achieve this?
EDIT:
To simplify: imagine class library encapsulating DAL. It talks to database. There are some costly queries inside. Some of them should be fetched once per user and stored somewhere and some of them could be used per Application (also stored to avoid future calls to DB). The thing is that normally I would use Cache, but since it's DAL class library, I want to include this functionality inside it (not in asp.net). Hope it's more clear now ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用缓存:
使用模式、接口等:
你的类库应该是松散耦合。 (易于交换且无交叉引用)
示例(我如何简化):
You should use caching:
Use Patterns, Interfaces etc:
Your class library should be loosely coupled. (Easy to exchange and no cross references)
Example (how I'm doing it simplified):