MassTransit and PreInsertEventListener or Interceptor

When a user on our web site creates a record, we use a PreInsertEventListener to look for an HttpContext. If one exists, we can extrapolate the user and time zone from the claims.

For MassTransit jobs, we don’t have an HttpContext. We are using PublishContext and ConsumeContext to pass user information. I would like to get this information to the PreInsertEventListener (or to a interceptor if you prefer).

How can I retrieve state beyond an HttpContext in the PreInsertEventListener or to an interceptor? I would like to consume a scoped class that stores this data, but since it’s scoped, I need to create a scope to get the service, and the state is lost.

Any help would be greatly appreciated.


I’m sorry, but what you’re asking seems to be beyond the scope of Hibernate: we only handle the arguments provided into the event listener itself. Any other state of your application must be handled by either yourself or another framework / library, as these HttpContext, PublishContext and ConsumeContext are not provided by Hibernate.

We might be able to help you if you share an example of what you’re trying to achieve, but with this little information I’m afraid we cannot give any recommendation.