Scoped instance (ISession NHibernate) is opening new sessions when using ConstructServicesUsing with DI #4020
Replies: 1 comment 1 reply
-
https://jimmybogard.com/automapper-usage-guidelines/ |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi @jbogard, would you have any idea how we could bind the session when trying to load a related entity from a custom converter using automapper? I've been facing a problem with that using DI (.net core). Since the session is created at any time when the dependency is necessary (the instance is Scoped), and when I resolve the entity using a custom converter on MyCustomConverter class it's in a different session, so if try to save it in my BaseRepository I getting an error like "[HibernateException: illegally attempted to associate a proxy with two open Sessions]"
The ISession instance is requested scoped, but when I try to get an instance of some repository from the current provider (ServiceCollection) in order to inject it into the custom converter, I get a null and I have to register it in a new provider scope and it is when the new ISession come up. My repositories are registered as transient.
Something like that.. just simplified for understanding
And in my customConverter
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions