I do NOT think we need these chains of method calls to get hold of
ApplicationContext
> ApplicationContext context =
>
> WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
if all we need in the end is "a reference" to the ApplicationContext,
why not inject it ?
@Autowired
ApplicationContext context;
and in the method, just one line:
> return context.getBean(clazz);
the complete code:
public class SpringServiceLocator implements ServiceLocator {
@Autowired
ApplicationContext context;
@Override
public Object getInstance(Class<?> clazz) {
return context.getBean(clazz);
}
I believe, there is only ONE ApplicationContext for the entire
lifetime of application.
therefore no matter what user/session makes a request, the application
context will be the same.
HttpRequest and Session, won't give us any more detail that we can't
otherwise obtain.
ApplicationContext becomes available on startup, we don't need all
those calls to get hold of it.
to summarize, that chain of method calls (getting hold of HttpRequest
and Session, and use of WebApplicationContextUtils)
can be all together avoided, and replaced by injecting
ApplicationContext directly.
what do you all think of this ?
isn't this what dependency injection is about ?
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.