设置会话工厂

发布于 2024-10-03 07:23:16 字数 627 浏览 3 评论 0原文

如何将 nservice 总线使用的当前会话工厂注入到自定义 saga 查找器中?

我已经使用以下代码初始化了 saga

NServiceBus.Configure.With()
                .CastleWindsorBuilder()
                .Sagas()
                .NHibernateSagaPersister()
                .XmlSerializer();

,并且我有一个 sagafinder

public sagafinder:saga<...>
{
 private ISessionFactory sessionFactory;

        public virtual ISessionFactory SessionFactory
        {
            get { return sessionFactory; }
            set { sessionFactory = value; }
        }
}

,但此会话工厂始终为空。 我知道我没有设置会话工厂。我该如何设置它?

谢谢, 阿贾伊

How can i inject the current session factory that is used by the nservice bus to a custom saga finder?

I have initialized the saga using the following code

NServiceBus.Configure.With()
                .CastleWindsorBuilder()
                .Sagas()
                .NHibernateSagaPersister()
                .XmlSerializer();

and i have a sagafinder

public sagafinder:saga<...>
{
 private ISessionFactory sessionFactory;

        public virtual ISessionFactory SessionFactory
        {
            get { return sessionFactory; }
            set { sessionFactory = value; }
        }
}

but this session factory is always coming as null.
I know i am not setting the session factory.How can i set it?

Thanks,
Ajai

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉溺在你眼里的海 2024-10-10 07:23:16

从这篇文章的发表时间来看,我假设您使用的是 NServiceBus 3 之前的版本,例如 2.6。

我一直在研究这个问题,为内置的 NHibernateSagaPersister 编写 Saga Finders 是一个难题。

NHibernateSagaFinder 使用已合并到 NServiceBus.Core.dll 中的 NHibernate Ilmerged 版本。因此,当您编写以下内容时(从默认的 saga finder 中摘录):

public class MySagaFinder : IFindSagas<MySaga>
{
    public NHibernate.ISession Session {get; set;}
    ...
}

这里的 ISession 将引用您引用的 NHibernate.dll 中的 ISession,而不是 NServiceBus 的内部 NHibernate。据我所知,不可能引用 NServiceBus.Core 的 NHibernate,因为它是“内部”的。这意味着 NServiceBus 使用的 IOC 容器要么不会注入会话,要么会注入错误的会话,具体取决于您的设置方式。

我已经研究这个问题有一段时间了,我认为最好的(唯一的)事情就是基于 NServiceBus 的内置 SagaFinder 创建您自己的自定义 SagaFinder。这应该不难做到,因为它位于 GitHub 的代码库中。

这可能会在更高版本的 NServiceBus (>=3) 中得到解决,但我不确定,因为我认为他们现在使用 RavenDB 来实现默认的传奇持久性。

Judging by the age of this post I'm going to assume that you are using a pre-3 version of NServiceBus like 2.6.

I have been looking into this and writing Saga Finders for the built in NHibernateSagaPersister is a hard problem.

The NHibernateSagaFinder uses an Ilmerged version of NHibernate that has been baked into NServiceBus.Core.dll. So when you write the following (ripped from the default saga finder):

public class MySagaFinder : IFindSagas<MySaga>
{
    public NHibernate.ISession Session {get; set;}
    ...
}

The ISession here will refer to the one in NHibernate.dll you have referrenced not NServiceBus's internal NHibernate. As far as I can tell it is not possible to reference NServiceBus.Core's NHibernate as it is "internal". This means that the IOC container that NServiceBus uses will either not inject a session or will inject the wrong one depending how you have it set up.

I have been looking into this for a while now and I think the best (only) thing to do is create your own custom SagaFinder based on the NServiceBus's built in one. This should not be to hard to do as it is in the code base on GitHub.

This may be fixed with later version of NServiceBus (>=3) but I'm not sure as I think they now use RavenDB for thier default saga persistance.

青柠芒果 2024-10-10 07:23:16

问题中的代码看起来根本不像传奇查找器。我所看到的只是一个传奇本身。如果您只是想根据消息中的某些属性查找传奇故事,那么亚当的建议是正确的。您不需要会话工厂,只需重写ConfigureHowToFindSaga()即可。如果您尝试做其他事情,那么 nhibernate saga 持久化器使用的会话工厂确实没有在您的容器中注册,以便您可以解决 saga 中的依赖关系。不过,您真正想要查询自己存储的传奇的可能性很小。因此,如果您确实有这样做的理由,我可能只是建议您自己为带有 saga 信息的数据库注册一个会话工厂,并让 nservicebus 拥有自己的会话工厂。但很难想象你真的想要这么做。

the code in the question does not look like a saga finder at all. what i see is a saga itself instead. if you are just trying to find the saga based on some property in the message, adam's suggestion is the correct one. you don't need the session factory and should just override ConfigureHowToFindSaga(). if you are trying to do something else, it is true that the session factory used by the nhibernate saga persister is not registered up with your container such that you can just resolve the dependency in your saga. chances are slim that you'd really want to query the saga stored yourself, though. so, if you really have a reason for it, i'd probably just suggest you register a session factory yourelf for the database with the saga information and let nservicebus have its own. hard to imagine you'd really want to, though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文