Subsonic、SharedDbConnectionScope 和 ApplicationState
我正在考虑将 Subsonic 与多租户 ASP.net Web 应用程序一起使用。有多个数据库(每个客户端/实例一个)。用户使用其用户名的域后缀登录(例如user@tenant1、user@tenant2)。
然后,自定义会员资格提供程序将确定用户正在使用哪个数据库,并对其进行身份验证。 Web 应用程序中所有用户发起的调用都将包装在 SharedDbConnectionScope 调用中,但是我有一个关于缓存亚音速项目的问题。
基本上每个实例都会有一些很少更改的记录(搜索选项/配置)。我想在 Application_Start 事件中读取这些,并将它们缓存到 ApplicationState 中。
在 Application_Start 事件中,它将循环遍历每个客户端数据库,使用 SharedDbConnectionScope 连接到每个数据库,并创建这些缓存记录(例如 Application('tenant1_search_obj') = subsonic_object
当用户加载搜索页面时,它会检查什么用户所在的域,然后从缓存中检索该搜索选项
是否可行?我只是担心如果我缓存一个对象,当我从应用程序缓存中检索它时,它不会知道它使用什么连接,并且可能会提取错误的数据,
如果可能的话,我想避免将其放入会话对象中。
I'm looking at using Subsonic with a multi-tenant ASP.net web application. There are multiple DB's (one per client/instance). The user logs in with a domain suffix to their username (e.g. user@tenant1, user@tenant2).
The custom membership provider will then determine which database a user is using, and authenticate against it. All user-initiated calls in the webapp will be wrapped in a SharedDbConnectionScope call, however I have a question regarding caching subsonic items.
Basically each instance will have a few records that rarely change (search options/configurations). I would like to read these in the Application_Start event, and cache them into the ApplicationState.
In the Application_Start event, it would loop over each client database, use a SharedDbConnectionScope to connect to each DB, and create these cached records (e.g. Application('tenant1_search_obj') = subsonic_object
When a user loads the search page, it would then check what domain a user is in, and then retreive that search option from the cache.
Is this feasible? I'm just concerned that if I cache an object, when I retrieve it from the application cache it won't know what connection its using, and might possibly pull in the wrong data.
I'd like to avoid putting this in the session object if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可能的,但可能不是一个好主意,因为它根本无法扩展 - 你将为每个客户端弹出一个新连接,无论它们是否出现。
也许您最好的选择是“延迟加载”设置 - 第一次点击搜索页面会将配置加载到缓存或应用程序设置中并保留在那里。
除此之外-回答你的问题是可能的。如果您使用的是 SubSonic 3,只需使用 ProviderFactory.GetProvider(connectionString, "System.Data.SqlClient") 即时创建一个新的提供程序,然后对其执行您的操作。
对于 SubSonic 2 - SharedConnectionScope 正是您想要的。
it's possible, but probably not a good idea since it doesn't scale at all - you're going to pop a new connection for every single client whether they show up or not.
Maybe your best bet is to "lazy load" the setting - first hit on the search page loads the config into the cache or Application settings and there it stays.
Other than that - to answer your question it is possible. If you're using SubSonic 3, just create a new provider on the fly using ProviderFactory.GetProvider(connectionString, "System.Data.SqlClient") and then execute your stuff against it.
For SubSonic 2 - SharedConnectionScope is what you want.