NHibernate with Microsoft.Extensions.DependencyInjection

73 views
Skip to first unread message

eric....@gmail.com

unread,
Sep 18, 2020, 2:52:47 AM9/18/20
to nhusers
Trying to use dependency injection with custom NHibernate implementation classes, specifically an IConnectionProvider. To be clear, I have NO interest in using DI with entities, just in a custom impl of a NHibernate interface.
I've read the (old) articles (here and here) and they sound promising, but the implementations are for Autofac, Spring, and Castle Windsor. Has nobody ever published an impl for .Net Core's "default" Microsoft.Extensions.DependencyInjection? I can't believe it hasn't been done before.

Any pointers?

Paulo Quicoli

unread,
Sep 18, 2020, 3:28:24 AM9/18/20
to nhusers
Hi

Is this what you are looking for?


--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nhusers/e5065fc5-f8d7-4e9d-a9c4-5951404f59fcn%40googlegroups.com.

Eric Rizzo

unread,
Sep 18, 2020, 11:33:43 AM9/18/20
to nhu...@googlegroups.com
No, not at all. That just covers one pattern for registering the ISession and ISessionFactory so they can be injected into DI-managed services (something I already have). What I need is for NH to use the DI container when creating the pieces it uses under the covers, such as IConnectionProvider.

Eric


You received this message because you are subscribed to a topic in the Google Groups "nhusers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nhusers/cdRA62nFo7I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nhusers+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nhusers/CAF8vUGU56OEVaptvh6xm%3D%2BwDzTXRb4_q59XRCpN0K5Tt1U5Xkw%40mail.gmail.com.

Alexander Zaytsev

unread,
Sep 19, 2020, 7:32:42 AM9/19/20
to nhu...@googlegroups.com
Unfortunately no one has done this for Micorosoft.Extensions.DependencyInjection. What you would need to do is to implement IObjectsFactory (check examples from Fabio's blog). There are only 3 or 4 methods.

Best Regards,
Alexander

eric....@gmail.com

unread,
Sep 21, 2020, 1:04:30 PM9/21/20
to nhusers
I looked at the implementations in Fabio's uNhAddIns project, and implementing IObjectsFactory is simple. But even looking at the NHibernate source code it's not clear how and when IBytecodeProvider and IReflectionOptimizer are used. I want to fully understand these interfaces and how they are used in order to make sure I'm implementing the MS.Extensions.DI "adapter" correctly and completely.
Is there any documentation about those?

Danny Van den Wouwer

unread,
Sep 21, 2020, 1:11:48 PM9/21/20
to nhu...@googlegroups.com
Hi,

There isn't much documentation about this interface. And I believe they are internally busy tot replace this interface in he next major version. See issue 1793, 1781.

You van Aldo read in this blog 

Vriendelijke groeten,
Van den Wouwer Danny

Software Engineer
Peopleware NV
www.peopleware.be

Op ma 21 sep. 2020 19:04 schreef eric....@gmail.com <eric....@gmail.com>:

eric....@gmail.com

unread,
Nov 5, 2020, 3:55:10 PM11/5/20
to nhusers
I implemented this pretty easily, and wrote about it at StackOverflow here, if anyone wants to see the basic impl (without optimizations that I later added).
Reply all
Reply to author
Forward
0 new messages