StructureMap 中具有多个 nHibernate Session 工厂的命名单例实例 (StructureMap 2.5.4)
我有完全相同的场景 StructureMap 中的命名单例实例(多个 nHibernate 会话工厂)
如果我使用 StructureMap 2.6.2 实现这一点 - 太棒了!
但是,由于遗留项目中涉及的各种因素无法使用最新的 .NET 框架版本以及其他一些原因,我目前必须使用 StructureMap 2.5.4。对于这个问题,假设我在可预见的将来无法升级。
2.5.4 显然在语法上与 2.6.2 有很大不同,我无法弄清楚如何使用它的 API 来实现相同的功能。
特别是,它是这个东西
For<ISessionFactory>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.Singleton))
.Add(context => CreateSessionFactory(@"MyName")).Named("MySessionFactory");
For<ISession>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.Hybrid))
.Add(context => context.GetInstance<ISessionFactory>("MySessionFactory").OpenSession()).Named("MyName");
For<ISessionFactory>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.Singleton))
.Add(context => CreateSessionFactory(@"My2ndName")).Named("My2ndSessionFactory");
For<ISession>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.Hybrid))
.Add(context => context.GetInstance<ISessionFactory>("MySessionFactory").OpenSession()).Named("My2ndName");
......使用名为 CreateSessionFactory(string) 的方法来创建相关配置。
“Add”和随后的“GetInstance”无效,需要重构才能与 2.5.4 一起使用 - 我太笨了,无法弄清楚如何实现,或者是否确实可以实现相同的目标。
干杯
I have the exact identical scenario as described in Named singleton instance in StructureMap (Multiple nHibernate session factories)
If I implement this using StructureMap 2.6.2 - great!
However, I have to currently use StructureMap 2.5.4 due to various factors involved in legacy projects not being able to use up-to-date .NET framework versions as well as a few other reasons. Assume for this question that I cannot upgrade for the forseeable future.
2.5.4 is obviously quite different in syntax to 2.6.2 and I can't work out how to implement the same thing using it's API.
In particular, it's this stuff
For<ISessionFactory>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.Singleton))
.Add(context => CreateSessionFactory(@"MyName")).Named("MySessionFactory");
For<ISession>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.Hybrid))
.Add(context => context.GetInstance<ISessionFactory>("MySessionFactory").OpenSession()).Named("MyName");
For<ISessionFactory>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.Singleton))
.Add(context => CreateSessionFactory(@"My2ndName")).Named("My2ndSessionFactory");
For<ISession>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.Hybrid))
.Add(context => context.GetInstance<ISessionFactory>("MySessionFactory").OpenSession()).Named("My2ndName");
...with a method called CreateSessionFactory(string) that creates the relevant configuration.
The "Add" and subsequent "GetInstance" are invalid and need to be refactored to work with 2.5.4 - I'm just too dumb to work out how, or if indeed you can achieve the same thing.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我记得你的语法应该在 2.5.4 中工作。对于 2.5.3,以下语法应该有效:
To my rememberance your syntax should work in 2.5.4. For 2.5.3 the following syntax should work: