Hibernate version: 2.0.1
What I want to achive is IoC constructor injection into my entities (the entity classes have a constructors that takes parameters which are interfaces of something that it has a dependency to). Now I am currently using StructureMap as IoC container but I think the problem should be the same with any container.
From google I gather that you can use IInterceptor.Instantiate to create instances rather than to have NH create them for you and everybody says that is the way to do contructor injection but I can find no samples how to do this. Looking at this
http://hendryluk.wordpress.com/2008/05/10/should-domain-entity-be-managed-by-ioc/ I found some sample code at the bottom of the page but it seems it is for an old version of IInterceptor:
Code:
public class Interceptor: IInterceptor
{
public object Instantiate(Type type, object id)
{
return IoC.Resolve(type);
}
}
The 2.0.1 version looks like this:
Code:
object Instantiate(String entityName, EntityMode entityMode, object id);
Now my interceptor class inherits from EmptyInterceptor and lives in a separate assembly from the domain classes. This leads me to my questions:
1. I can find no way to convert the "String entityName" parameter to type object because the string does not contain the assembly name. How do I get a type object from only the full classname without knowing which assembly the entity lives in?
2. If I create my own objects through IInterceptor.Instantiate using an IoC container will that interfere with the whole proxy-lazy-load stuff that NHibernate provides?
After spending hours trying to google for these questions I would be grateful for any answers!