I've made a bit of progress. First of all, I realized that I don't need
database access for my AccessController (Dispatcher) since it will
simply need to check a User object for roles, etc. This object would be
created/destroyed by a login page. I did figure out an acceptable way to
get at the Session at any rate, so here's what I did.
tapestry-hibernate provides the "HibernateSessionManager" service, which
is represented by an interface of the same name. So in my AppModule I
have a builder method that basically does this:
public Dispatcher buildAccessController(@Inject HibernateSessionManager
sessionManager) {
return new AccessControllerImpl(sessionManager);
}
The builder is provided with the tapestry-ioc HibernateSessionManager
service, which then passes this instance to my AccessController.
According to the source of HibernateSessionManager, the implementation
provides a Session for the current thread via:
HibernateSessionManager#getSession
So now that my AccessController has this service, it can simply call
getSession() anytime it needs a Session.
I'm now dealing with a different (architectural) issue, but that's for
another message ;). I hope someone finds this useful!
sincerely,
chris
Chris Lewis wrote:
Hi all,
I'm implementing an access control service as a Dispatcher, and
contributing it to the MasterDispatcher service. This dispatcher runs
just before PageRender... and ComponentAction..., so that it can check
if the user is allowed to access the page/resource. This seems to be a
very "T5" way of doing things and completely removes the task of
access control from the pages (ie i don't have to extend a base page
that implements control logic).
I want this service to use a database and am already using
tapestry-hibernate in this project. I figured I could just @Inject the
session into my service just like I would a page or component, but
that doesn't work. In a way that makes sense; services are singletons
if I'm not mistaken (which makes sense), and Sessions exist (and
possibly injected?) per-thread. Being that my service will be started
in a different thread than any request, I think @Inject is ignored.
So my question is, how should I go about getting access to my database
from my service? I'd like to use the blinding simplicity of of IoC
just giving it to me, but I;m not sure that's an option. Any ideas?
thanks,
chris
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]