如何更改 Castle ActiveRecord 使用的连接
我有一个使用 ActiveRecord 构建的应用程序,其中有一个新要求,即允许用户在应用程序运行过程中的不同时间选择他们希望操作的数据库。
数据库连接是在 ActiveRecordStart.Initalize 调用中设置的。 我希望每当用户选择使用新数据库时都能够更改此连接。 但是,我看不出有什么办法可以做到这一点。
DifferentDatabaseScope 确实允许使用不同的连接,但只会覆盖 Initialize 调用中的连接设置,并且必须用于每个 ActiveRecord 调用,数量为数百个,因此不太理想。
我不知道有什么方法可以更改在初始化中设置的“基本”连接吗?
I have an application build using ActiveRecord for which there is a new requirement to allow the user to select a database they wish to operate at various times in the course of the running of the application.
The database connection is set up in the ActiveRecordStart.Initalize call. I would like to be able to change this connection whenever the user selects to work with a new database. However, I can see no way of doing this.
DifferentDatabaseScope does allow the use of a different connection, but only overrides the connection setup in the Initialize call and has to be used for each ActiveRecord call, which number hundreds, so is less than ideal.
This there some way I am not aware of to change the 'base' connection that is set up in the Initialize?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不同的数据库范围还不够,请尝试编写自定义
IConnectionProvider< /a>创建一个指向用户选择的数据库的 IDbConnection。If Different Database Scope is not enough try writing a custom
IConnectionProviderthat creates a IDbConnection pointing to the user-selected database.