You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Steve Tarlton <st...@gmail.com> on 2009/07/17 20:27:20 UTC

SpringBean: component-based verses session in scope.

My app is using Spring/Hibernate and I am using the @SpringBean annotation
based dependency injection to tie in my services. During my development, I
found I needed access to one of the services at the session layer and found
a thread that discussed how to do that by calling out
"InjectorHolder.getInjector().inject(this);" in the init when constructing
the session.

Now I am wondering if it is more optimal to move all of my other service
lookup injectors to the session scope. To me, it seems that this would be
more optimal as the app would only need to inject the service once as
opposed to potentially many times if replicated within several components.
However, the trade-off may be holding service-level data at a session level,
thus sticking around for the life of the session. Is this a correct
analysis, or is it simply good practice to create injectors to services at
the session layer so that only one instance is ever created for a given
session?

Re: SpringBean: component-based verses session in scope.

Posted by Igor Vaynberg <ig...@gmail.com>.
erm. i meant

matrixCheckItemService.foo()

-igor

On Fri, Jul 17, 2009 at 12:08 PM, Igor Vaynberg<ig...@gmail.com> wrote:
> what gets injected into the component and what gets injected into
> session are the *same* thing - a pointer to something in the spring
> context.
>
> so why would you want to write
>
> MatrixCheckItemService matrixCheckItemService =
> ((MatrixSession)WebSession.get()).getCheckItemService();
>
> when you can just write
> matrixCheckItemService.getCheckItemService()
>
> ?
>
> -igor
>
> On Fri, Jul 17, 2009 at 12:04 PM, satar<st...@gmail.com> wrote:
>>
>> Igor, I was more asking for opinions on whether it better to define my
>> @SpringBean injections in my session class verses within components that
>> need them. In the later, I may end up injecting the same session class in
>> more than one component class. What I am doing now is moving those instances
>> out into the session class and accessing within the component with a call to
>> a session-level method:
>>
>> ...
>>    // get our Check items from the database
>>    MatrixCheckItemService matrixCheckItemService = ((MatrixSession)
>> WebSession
>>        .get()).getCheckItemService();
>> ...
>>
>> I have a working solution either way. I was just looking for insight on what
>> smart, highly knowledgeable peeps like yourself thought was better.
>> --
>> View this message in context: http://www.nabble.com/SpringBean%3A-component-based-verses-session-in-scope.-tp24539500p24539994.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: SpringBean: component-based verses session in scope.

Posted by Igor Vaynberg <ig...@gmail.com>.
if you declare the service reference as a component field with
@SpringBean then it is directly accessible within your component code.

-igor

On Fri, Jul 17, 2009 at 12:49 PM, satar<st...@gmail.com> wrote:
>
> Oh... I see, so it doesn't matter which way I go because underneath the
> covers it is a single instance of the session anyway. Still less code to
> manage/write if I define access to the injected sessions within the session
> class. Now I just need to learn and understand what you meant by the comment
> why not use:
>
>  matrixCheckItemService.foo()
>
> That one is throwing me but I am fairly new with web architectures period so
> I probably am not reading into that. What I am doing with:
>
> MatrixCheckItemService matrixCheckItemService =
> ((MatrixSession)WebSession.get()).getCheckItemService();
>
> is getting a pointer to my service that I injected within my session class,
> then I call matrixCheckItemService.foo(). Are you suggesting that I make the
> session's injected instance public instead of private beings there can only
> be one session level instance anyway because it is handled underneath the
> covers at the spring context?
>
> Sorry if I appear ignorant... I am still very green behind the ears.
>
>
> --
> View this message in context: http://www.nabble.com/SpringBean%3A-component-based-verses-session-in-scope.-tp24539500p24540596.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: SpringBean: component-based verses session in scope.

Posted by satar <st...@gmail.com>.
Oh... I see, so it doesn't matter which way I go because underneath the
covers it is a single instance of the session anyway. Still less code to
manage/write if I define access to the injected sessions within the session
class. Now I just need to learn and understand what you meant by the comment
why not use:

  matrixCheckItemService.foo()

That one is throwing me but I am fairly new with web architectures period so
I probably am not reading into that. What I am doing with:

MatrixCheckItemService matrixCheckItemService =
((MatrixSession)WebSession.get()).getCheckItemService();

is getting a pointer to my service that I injected within my session class,
then I call matrixCheckItemService.foo(). Are you suggesting that I make the
session's injected instance public instead of private beings there can only
be one session level instance anyway because it is handled underneath the
covers at the spring context?

Sorry if I appear ignorant... I am still very green behind the ears.


-- 
View this message in context: http://www.nabble.com/SpringBean%3A-component-based-verses-session-in-scope.-tp24539500p24540596.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: SpringBean: component-based verses session in scope.

Posted by Igor Vaynberg <ig...@gmail.com>.
what gets injected into the component and what gets injected into
session are the *same* thing - a pointer to something in the spring
context.

so why would you want to write

MatrixCheckItemService matrixCheckItemService =
((MatrixSession)WebSession.get()).getCheckItemService();

when you can just write
matrixCheckItemService.getCheckItemService()

?

-igor

On Fri, Jul 17, 2009 at 12:04 PM, satar<st...@gmail.com> wrote:
>
> Igor, I was more asking for opinions on whether it better to define my
> @SpringBean injections in my session class verses within components that
> need them. In the later, I may end up injecting the same session class in
> more than one component class. What I am doing now is moving those instances
> out into the session class and accessing within the component with a call to
> a session-level method:
>
> ...
>    // get our Check items from the database
>    MatrixCheckItemService matrixCheckItemService = ((MatrixSession)
> WebSession
>        .get()).getCheckItemService();
> ...
>
> I have a working solution either way. I was just looking for insight on what
> smart, highly knowledgeable peeps like yourself thought was better.
> --
> View this message in context: http://www.nabble.com/SpringBean%3A-component-based-verses-session-in-scope.-tp24539500p24539994.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: SpringBean: component-based verses session in scope.

Posted by satar <st...@gmail.com>.
Igor, I was more asking for opinions on whether it better to define my
@SpringBean injections in my session class verses within components that
need them. In the later, I may end up injecting the same session class in
more than one component class. What I am doing now is moving those instances
out into the session class and accessing within the component with a call to
a session-level method:

...
    // get our Check items from the database
    MatrixCheckItemService matrixCheckItemService = ((MatrixSession)
WebSession
        .get()).getCheckItemService();
...

I have a working solution either way. I was just looking for insight on what
smart, highly knowledgeable peeps like yourself thought was better.
-- 
View this message in context: http://www.nabble.com/SpringBean%3A-component-based-verses-session-in-scope.-tp24539500p24539994.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: SpringBean: component-based verses session in scope.

Posted by Igor Vaynberg <ig...@gmail.com>.
spring provides a scoping mechanism and supports session scope out of
the box. why dont you google around for that, might save you some
headaches.

-igor

On Fri, Jul 17, 2009 at 11:27 AM, Steve Tarlton<st...@gmail.com> wrote:
> My app is using Spring/Hibernate and I am using the @SpringBean annotation
> based dependency injection to tie in my services. During my development, I
> found I needed access to one of the services at the session layer and found
> a thread that discussed how to do that by calling out
> "InjectorHolder.getInjector().inject(this);" in the init when constructing
> the session.
>
> Now I am wondering if it is more optimal to move all of my other service
> lookup injectors to the session scope. To me, it seems that this would be
> more optimal as the app would only need to inject the service once as
> opposed to potentially many times if replicated within several components.
> However, the trade-off may be holding service-level data at a session level,
> thus sticking around for the life of the session. Is this a correct
> analysis, or is it simply good practice to create injectors to services at
> the session layer so that only one instance is ever created for a given
> session?
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org