-->
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.  [ 2 posts ] 
Author Message
 Post subject: Can NHibernate inflate entities via a Castle IoC container?
PostPosted: Fri Sep 28, 2007 8:42 pm 
Newbie

Joined: Sat Jun 09, 2007 7:41 am
Posts: 4
Location: Melbourne
I'm currently working on a web solution using NHibernate for persistence and Castle Windsor for IoC/DI.

Castle is taking care of providing services to the UI (a form of MVP) including business logic, actions to perform CRUD and validation. NHibernate is mapping POCOs into the database.

This is coming together nicely, but it seems that I have architectured my solution using the "anemic domain model" anti-pattern. I.e. my POCOs are dumb value objects being passed around the application, rather than encapsulating business rules.

The reason I've ended up with this anemic model is that NHibernate is not the only back-end consumer of the domain objects, and the business rules and actions have differing implementations for different consumers. E.g. I might get objects from a TIBCO ESB with one implementation and a DB via NHibernate with another.

Consequently I can't code business actions and validations directly into the POCO as they vary (which is where Castle Windsor enters the scene). Same action or rule, different implementation.

It works, but can I do better?

So, I'm wondering if NHibernate supports the loading of entities through the Castle container? Then I can move business logic (actions) and validation into (closer?) to the domain objects (i.e. NHibernate will delegate object creation to Castle, which will satisfy dependencies specified as constructor arguments or properties). NHibernate could then fill in mapped data. I'm kinda hoping for an ICustomLoader interface!

I admit I haven't really thought this through. Does it seem a reasonable idea? And if NH doesn't currently support this type of behaviour can someone point me to likely namespaces (NHibernate.Loader and NHibernate.Persister look promising) and any doco on the way NH builds objects? Would lazy initialisation cause problems?

Am I making sense? Any input appreciated!

Regards,

Andy.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 4:57 am 
Beginner
Beginner

Joined: Tue May 02, 2006 8:04 am
Posts: 34
Whenever I need to inject something in the domain objects, I use an interceptor where I can control instantiation. The interceptor delegates to the DI framework.


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

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.