Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constructor dependency injection with NHibernate 2.1 and StructureMap

I've read somewhere that NHibernate 2.1 supports constructor dependency injection for it's entites.

How do I go about configuring StructureMap and NHibnerate 2.1 to get this up and running ?

like image 372
BjartN Avatar asked Nov 06 '22 20:11

BjartN


1 Answers

I realize this is an old question, but in case it might be useful.

EDIT: Original posted links weren't effective for NHib 2.1, found better info.

For NHibernate 2.1, you can create an Interceptor and override the Instantiate method and have your container create your instances there. Here is an example

If you wanted to do property injection instead, you can use the same technique but do your work in the onLoad method instead.

like image 132
Remi Despres-Smyth Avatar answered Nov 14 '22 22:11

Remi Despres-Smyth