Re: ByteCodeProviders and IUserType parameters in NHibernate 3.3

115 views
Skip to first unread message

Ricardo Peres

unread,
Jun 13, 2012, 12:36:03 PM6/13/12
to nhu...@googlegroups.com
You could use StructureMap to register your service and Common Service Locator, so that you don't have a dependency on StructureMap, inside the IUserType to retrieve your object.
But probably it would be better to have an event listener, for pre-load event, for example, and in there set a public property on your IUserType.

Just my 5 cents...

RP


On Wednesday, June 13, 2012 3:55:20 PM UTC+1, Matt Mueller wrote:
Hi, everyone. I'm a new member to the list and I'm hoping you can help me understand a problem that has plagued me for days. In my ASP MVC application I have a User type that is not persisted to the database but that I instead want to retrieve from Active Directory. I have a service for this purpose and I have an IUserType defined for the User entity that represents it as just an Id in the database but that returns a complete User object. The only thing I cannot figure out is how to supply my UserService to the IUserType. The process I see recommended most is to use a custom ByteCodeProvider with NHibernate. But some sources seem to indicate that these are not supported after version 3.2. I can't find any good documentation so could someone explain to me how to supply a service or other parameter to an IUserType. Ideally I would like it to be supply via StructureMap as it handles dependencies in the rest of my app. This is my first time around with NHibernate so any help or clarification you can give is greatly appreciated. 

Matt Mueller

unread,
Jun 13, 2012, 2:47:04 PM6/13/12
to nhu...@googlegroups.com
Using an event listener is something I considered and implemented. However, The user is usually not loaded directly but rather as a member of several other objects. So using the event model yields the parent entity and then I have to provide logic to update the right properties depending on the type and the object graph. Including the service at the level of the type avoids that and it seemed cleaner to me. I just haven't found a way to provide a service to the type since it must have a null constructor. Using a service locator isn't a technique I've got experience with. Would that get around the constructor issue?
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/E1k8WI0bHO4J.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Matt Mueller

unread,
Jun 14, 2012, 12:20:26 PM6/14/12
to nhu...@googlegroups.com
Hello again. After continued searching, I have come across NHibernate.DependencyInjection in the Nuget package manager. It looks to do just what I need for the latest versions of NHibernate. Does anyone know what I need to do to configure this? Can it be done fluently or does it have to be done in XML? I'm hoping maybe some others may have used this that could share their experience. Thanks as always. 

Darren Kopp

unread,
Jun 14, 2012, 2:07:47 PM6/14/12
to nhu...@googlegroups.com
NHibernate.Cfg.NHibernate.ByteCodeProvider = (your instance here)

Free-handing that, so property might be slightly different, but intellisense will take care of it for you. Just make sure that is set before you build your configuration. 
Reply all
Reply to author
Forward
0 new messages