These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Questions about using IInterceptor.Instantiate for IoC
PostPosted: Thu Feb 05, 2009 1:57 pm 
Newbie

Joined: Tue Jul 29, 2008 5:11 am
Posts: 5
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.