summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/dagger/DaggerContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/gitblit/dagger/DaggerContext.java')
-rw-r--r--src/main/java/com/gitblit/dagger/DaggerContext.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main/java/com/gitblit/dagger/DaggerContext.java b/src/main/java/com/gitblit/dagger/DaggerContext.java
index 0e6a3fc4..ef570804 100644
--- a/src/main/java/com/gitblit/dagger/DaggerContext.java
+++ b/src/main/java/com/gitblit/dagger/DaggerContext.java
@@ -17,11 +17,12 @@ package com.gitblit.dagger;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.gitblit.servlet.InjectionContextListener;
+
import dagger.ObjectGraph;
/**
@@ -31,7 +32,7 @@ import dagger.ObjectGraph;
* @author James Moger
*
*/
-public abstract class DaggerContext implements ServletContextListener {
+public abstract class DaggerContext extends InjectionContextListener {
public static final String INJECTOR_NAME = ObjectGraph.class.getName();
@@ -58,6 +59,23 @@ public abstract class DaggerContext implements ServletContextListener {
return (ObjectGraph) o;
}
+ /**
+ * Instantiates an object.
+ *
+ * @param clazz
+ * @return the object
+ */
+ @Override
+ protected <X> X instantiate(ServletContext context, Class<X> clazz) {
+ try {
+ ObjectGraph injector = getInjector(context);
+ return injector.get(clazz);
+ } catch (Throwable t) {
+ logger.error(null, t);
+ }
+ return null;
+ }
+
@Override
public final void contextDestroyed(ServletContextEvent contextEvent) {
ServletContext context = contextEvent.getServletContext();