如何实现多数据库的存储库模式
我们目前有两个演示项目(经典 ASP 和 ASP.NET,其中使用了“NHibernate Best Practices with ASP.NET”(前身或 Sharp 架构)。我们现在正在使用 Silverlight + WCF(可能是 RIA 服务)重写所有经典 ASP我们
有以下数据库架构: * 一个全球数据数据库 - 包含用户和项目元信息 * 每个项目都有自己的数据库来存储特定于项目的信息 - 相同的模式
我们能够进行一些修改以使多个数据库在 ASP.NET 中工作,因为“NHibernate Best Practices with ASP.NET”使用 DAO 工厂,我们可以修改它创建连接字符串 - 基于projectId - 传递到工厂以创建相应的 NHibernate 会话。
对于重写,我们希望使用 Sharp 架构中的存储库模式。但我们不知道如何进行类似的黑客攻击...
任何帮助都是值得赞赏的。
We currently have two presentation projects (classic ASP and ASP.NET, which uses the "NHibernate Best Practices with ASP.NET" (predecessor or Sharp architecture). We are now rewrite all the classic ASP with Silverlight + WCF(maybe RIA services).
We have the following database architecture:
* one global data database - contains users and projects meta info
* each project has its own database to store project-specific info - same schema
We were able to hack a bit to make multiple databases work in ASP.NET because "NHibernate Best Practices with ASP.NET" uses DAO factories, which we can hack a bit to create the connection string - base on the projectId - to pass to the factory to create the corresponding NHibernate session.
For the rewrite, we would like to use the repository pattern from Sharp architecture. But we couldn't figure out how to do the similar hack...
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看一下 ncommon 框架,它为 NHibernate 中的多数据库支持提供了良好的基础,如下所述博客文章。
Have a look at the ncommon framework which provides a nice foundation for multi-database support in NHibernate as explained in this blog post.
我对 Sharp Architecture 进行了一些修改,并在 我的帖子。希望它能帮助你。
I have hacked a little bit to Sharp Architecture and re-built it for multiple database in my post. Hope it will help you.
无论您使用哪种模式,ISessionFactory 都会处理连接。使用具有某种形式的命名或可选参数的 IoC 容器来指定连接字符串。
No matter what pattern you are using the ISessionFactory handles the connection. Use an IoC container with some form of named or optional parameters to specify the connection string.