The DAO reference will never be null. It might be a proxy that points to a null implementation. The proxy will instantiate the DAO implementation the first time a method is invoked on the proxy.
You can use @EagerLoad to load your DAO at app startup to avoid lazy loading. On 1 May 2013 11:07, "John" <j...@quivinco.com> wrote: > Thanks for this, it does work. :) > > I'm disliking that I have to have a request to get the servlet context > though, this makes the instantiation a bit messy as I have to check the dao > reference is not null. > > John > ----- Original Message ----- > From: Taha Hafeez Siddiqi > To: Tapestry users > Sent: Wednesday, May 01, 2013 9:55 AM > Subject: Re: SessionListener interacting with Tapestry services? > > > Hi John > > You can directly extract the registry from the ServetContext > > using > http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/TapestryFilter.html#REGISTRY_CONTEXT_NAME > > > Note: NOT TESTED > > public class MyListener implements HttpServletListener { > > public void sessionCreated(HttpServletRequest e){ > Registry registry = > (Registry)e.getSession().getServletContext().getAttribute(TapestryFilter.REGISTRY_CONTEXT_NAME); > MyDAO dao = registry.getService(MyDAO.class); > } > > } > > regards > Taha > > > > On 01-May-2013, at 2:19 PM, John <j...@quivinco.com> wrote: > > > I configure a SessionListener in web.xml: > > > > <listener> > > > > <listener-class>epulse.audit.manager.SessionListener</listener-class> > > > > </listener> > > > > And in the listener I have directly wired the Logger so: > > > > public class SessionListener implements HttpSessionListener { > > > > > > /** The log. */ > > > > private static Logger log = Logger.getLogger(SessionListener.class); > > > > > > /** The audit log. */ > > > > @Inject > > > > private AuditDAO auditDAO; > > > > > > I now want to inject a DAO to perform auditing but of course the > SessionListener is managed by the web container, what to do? > > > > As it happens at present the audit log is just a wrapper service for > SLF4j so I can directly instantiate the audit logging the same as the > regular log. > > > > John > >