Constructor dependency injection with NHibernate 2.1 and StructureMap

I read somewhere that NHibernate 2.1 supports the dependency injection of the constructor for which it is requesting.

How do I configure StructureMap and NHibnerate 2.1 to run it?

+5
source share
2 answers

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

EDIT: the original links were not effective for NHib 2.1, found the best information.

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

, , onLoad.

+2

StructureMap ( ..), ... , StructureMap !

[PluginFamily("Default")]
public interface IWidget1

[Pluggable("Default")]
public class Widget1 : IWidget1

[PluginFamily("Default")]
public interface IAnotherWidget

[Pluggable("Default")]
public class AnotherWidget : IAnotherWidget
{
    public AnotherWidget(IWidget widget)
    {
       ...
    }
}

IAnotherWidget _anotherWidget = ObjectFactory.GetInstance<IAnotherWidget>();

- !

: Activator.CreateInstance() NHibernate?

: http://devlicio.us/blogs/billy_mccafferty/archive/2007/02/05/inject-di-container-into-domain-objects-with-nhibernate.aspx

0

All Articles