Object Tress and SessionWrapper wire()

6 views
Skip to first unread message

John Allen

unread,
Dec 8, 2011, 2:15:47 PM12/8/11
to coldspri...@googlegroups.com
Hey Group,
I am SUPER enjoying the new ColdSpring 2. A really great piece of work.

I have an approach question for you smart developers, and I'll use the model of a Blog to illustrate:
  1. I'm in the middle of saving a Post object.
  2. I want to check which Blog the post belongs to so I get it using post.getBlog().
  3. Because I'm getting the Blog object from the Posts object graph, it isn't "wired" with its dependencies because I'm not getting it from the SessionWrapper which is using the BeanInjector for my transients.

To fix the situation: in my Blog objects init method I'm setting the dependencies by reaching out to CS (in the application scope) and getting the beans from there. While this works fine, and still follows the single point of access pattern, I just don't like the approach that much.

Anyone else have a similar situation and another way around it?

Thanks
John Allen


Tony Nelson

unread,
Dec 8, 2011, 2:19:25 PM12/8/11
to ColdSpring-Users
You could use a global ORM EventHandler to inject the dependencies
using either a preLoad() or postLoad() event.

On Dec 8, 1:15 pm, John Allen <johnfal...@gmail.com> wrote:
> Hey Group,
> I am SUPER enjoying the new ColdSpring 2. A really great piece of work.
>
> I have an approach question for you smart developers, and I'll use the
> model of a Blog to illustrate:
>

>    1. I'm in the middle of saving a Post object.
>    2. I want to check which Blog the post belongs to so I get it using
>    post.getBlog().
>    3. Because I'm getting the Blog object from the Posts object graph, it

John Allen

unread,
Dec 8, 2011, 4:10:46 PM12/8/11
to coldspri...@googlegroups.com
Thanks for the suggestion and I have tried that, but I'm finding an issue which seems like odd behavior for ORM.

In postLoad() I'm using the beanInjector to wire up the entity, BUT the entity that is finally returned from ORM is NOT being wired. Matter of fact, I can't modify the entity at all in the EventHandler.

I would think that the entity being passed to the postLoad() is the same entity that is returned form ORM. Maybe I'm crazy.


--
You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.
To post to this group, send email to coldspri...@googlegroups.com.
To unsubscribe from this group, send email to coldspring-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coldspring-users?hl=en.


Tony Nelson

unread,
Dec 8, 2011, 4:14:38 PM12/8/11
to coldspri...@googlegroups.com
Have you verified your EventHandler is working correctly? And you have code looks something like the following?

public void function preLoad(any entity) {
    application.beanFactory.getBean("beanInjector").autowire(arguments.entity);
}


-Tony

Mark Mandel

unread,
Dec 8, 2011, 4:14:19 PM12/8/11
to coldspri...@googlegroups.com
John, 

Are you using the BeanInjectorEventHandler?

Or your own event handler?

What dependency are you looking to inject? Some sort of Service object, or something else?

Mark

John Allen

unread,
Dec 8, 2011, 4:52:10 PM12/8/11
to coldspri...@googlegroups.com
@Mark OOPS! No I was just using the BeanInjector. Didn't see BeanInjectorEventHandler

BeanInjectorEventHandler works like a champ! And yes, I was inserting Service/Config objects. I like me some smart domain objects.

Maybe next time I'll _really_ try to read the documentation.

Thanks!

John Allen

unread,
Dec 8, 2011, 4:57:57 PM12/8/11
to coldspri...@googlegroups.com
And one more thing...

@Mark - this version of ColdSpring IS TOTALLY COOL!

So thanks millions and billions.
Reply all
Reply to author
Forward
0 new messages