Commits

Sam Adams  committed 6967830

Fix config injection

  • Participants
  • Parent commits d3f1670

Comments (0)

Files changed (9)

File chempound-app/src/main/java/net/chempound/AbstractChempoundConfigurationModule.java

+package net.chempound;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import net.chempound.config.*;
+
+import java.io.File;
+import java.net.URI;
+
+/**
+ * @author Sam Adams
+ */
+public abstract class AbstractChempoundConfigurationModule extends AbstractModule {
+
+    @Provides
+    @Singleton
+    @BaseUri
+    public URI getBaseUri(final ChempoundConfiguration configuration) {
+        return configuration.getBaseUri();
+    }
+
+    @Provides
+    @Singleton
+    @SwordUri
+    public URI getSwordUri(final ChempoundConfiguration configuration) {
+        return configuration.getBaseUri().resolve("sword/");
+    }
+
+    @Provides
+    @Singleton
+    @ContentUri
+    public URI getContentUri(final ChempoundConfiguration configuration) {
+        return configuration.getBaseUri().resolve("content/");
+    }
+
+    @Provides
+    @Singleton
+    @CacheDirectory
+    public File getCacheDirectory(final ChempoundConfiguration configuration) {
+        return configuration.getCacheDirectory();
+    }
+}

File chempound-app/src/main/java/net/chempound/ChempoundConfigurationModule.java

-package net.chempound;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Provides;
-import net.chempound.config.*;
-
-import java.io.File;
-import java.net.URI;
-
-/**
- * @author Sam Adams
- */
-public class ChempoundConfigurationModule extends AbstractModule {
-
-    private final ChempoundConfiguration configuration;
-    private final PropertySource propertySource;
-
-    public ChempoundConfigurationModule(final PropertySource propertySource) {
-        this(new DefaultChempoundConfiguration(propertySource), propertySource);
-    }
-
-    public ChempoundConfigurationModule(final ChempoundConfiguration configuration, final PropertySource propertySource) {
-        this.configuration = configuration;
-        this.propertySource = propertySource;
-    }
-
-    @Override
-    protected void configure() {
-        bind(PropertySource.class).toInstance(propertySource);
-        bind(ChempoundConfiguration.class).toInstance(configuration);
-    }
-
-    @Provides
-    @BaseUri
-    public URI getBaseUri() {
-        return configuration.getBaseUri();
-    }
-
-    @Provides
-    @SwordUri
-    public URI getSwordUri() {
-        return configuration.getBaseUri().resolve("sword/");
-    }
-
-    @Provides
-    @ContentUri
-    public URI getContentUri() {
-        return configuration.getBaseUri().resolve("content/");
-    }
-
-
-    @Provides
-    @CacheDirectory
-    public File getCacheDirectory() {
-        return configuration.getCacheDirectory();
-    }
-
-}

File chempound-webapp/src/main/java/net/chempound/webapp/ChempoundWebappModule.java

 package net.chempound.webapp;
 
 import com.google.inject.AbstractModule;
-import net.chempound.ChempoundConfigurationModule;
 import net.chempound.DefaultChempoundModule;
-import net.chempound.config.DefaultPropertySource;
-import net.chempound.config.PropertySource;
 import net.chempound.datastore.JenaTripleStoreModule;
 import net.chempound.storage.FileSystemResourceStoreModule;
 
         installPlugins();
     }
 
-    protected PropertySource getPropertySource() {
-        return new DefaultPropertySource();
-    }
-
     protected void installConfigurationModule() {
-        install(new ChempoundConfigurationModule(getPropertySource()));
+        install(new DefaultChempoundConfigurationModule());
     }
 
     protected void installChempoundModule() {

File chempound-webapp/src/main/java/net/chempound/webapp/DefaultChempoundConfigurationModule.java

+package net.chempound.webapp;
+
+import net.chempound.AbstractChempoundConfigurationModule;
+import net.chempound.config.ChempoundConfiguration;
+import net.chempound.config.DefaultChempoundConfiguration;
+import net.chempound.config.DefaultPropertySource;
+import net.chempound.config.PropertySource;
+
+public class DefaultChempoundConfigurationModule extends AbstractChempoundConfigurationModule {
+
+    private final PropertySource propertySource;
+
+    public DefaultChempoundConfigurationModule() {
+        this(new DefaultPropertySource());
+    }
+
+    public DefaultChempoundConfigurationModule(final PropertySource propertySource) {
+        this.propertySource = propertySource;
+    }
+
+    @Override
+    protected void configure() {
+        bind(ChempoundConfiguration.class).toInstance(new DefaultChempoundConfiguration(propertySource));
+    }
+}

File chempound-webapp/src/main/java/net/chempound/webapp/ServletConfigurationModule.java

-package net.chempound.webapp;
-
-import net.chempound.ChempoundConfigurationModule;
-import net.chempound.webapp.config.ServletPropertySource;
-
-import javax.servlet.ServletContext;
-
-public class ServletConfigurationModule extends ChempoundConfigurationModule {
-
-    public ServletConfigurationModule(final ServletContext context) {
-        super(new ServletPropertySource(context));
-    }
-
-}

File chempound-webapp/src/main/java/net/chempound/webapp/ServletContextChempoundConfigurationModule.java

+package net.chempound.webapp;
+
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import net.chempound.AbstractChempoundConfigurationModule;
+import net.chempound.config.ChempoundConfiguration;
+import net.chempound.config.DefaultChempoundConfiguration;
+import net.chempound.config.PropertySource;
+import net.chempound.webapp.config.ServletPropertySource;
+
+import javax.servlet.ServletContext;
+
+public class ServletContextChempoundConfigurationModule extends AbstractChempoundConfigurationModule {
+
+    @Override
+    protected void configure() {
+    }
+
+    @Provides
+    @Singleton
+    public PropertySource getPropertySource(final ServletContext servletContext) {
+        return new ServletPropertySource(servletContext);
+    }
+
+    @Provides
+    @Singleton
+    public ChempoundConfiguration getChempoundConfiguration(final PropertySource propertySource) {
+        return new DefaultChempoundConfiguration(propertySource);
+    }
+}

File chempound-webapp/src/main/java/net/chempound/webapp/StubChempoundConfigurationModule.java

+package net.chempound.webapp;
+
+import net.chempound.AbstractChempoundConfigurationModule;
+import net.chempound.config.ChempoundConfiguration;
+
+public class StubChempoundConfigurationModule extends AbstractChempoundConfigurationModule {
+
+    private final ChempoundConfiguration configuration;
+
+    public StubChempoundConfigurationModule(final ChempoundConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    @Override
+    protected void configure() {
+        bind(ChempoundConfiguration.class).toInstance(configuration);
+    }
+}

File chempound-webapp/src/main/java/net/chempound/webapp/StubConfigurationWebAppModule.java

 
 import com.google.inject.AbstractModule;
 import com.google.inject.Module;
-import net.chempound.ChempoundConfigurationModule;
 import net.chempound.config.ChempoundConfiguration;
-import net.chempound.config.DefaultPropertySource;
 import net.chempound.config.StubChempoundConfiguration;
 import net.chempound.datastore.InMemoryJenaTripleStore;
 import net.chempound.datastore.TripleStore;
     @Override
     protected void installConfigurationModule() {
         final ChempoundConfiguration configuration = new StubChempoundConfiguration(baseUri, workspace);
-        install(new ChempoundConfigurationModule(configuration, new DefaultPropertySource()));
+        install(new StubChempoundConfigurationModule(configuration));
     }
 
     @Override

File chempound-webapp/src/main/java/net/chempound/webapp/guice/GuiceServletModule.java

 
 import com.google.inject.servlet.ServletModule;
 
-import javax.servlet.ServletContext;
-
 /**
 * @author sea36
 */
     @Override
     protected void configureServlets() {
         serve("/*").with(GuiceRestletServlet.class);
-
-        bind(ServletContext.class).toInstance(getServletContext());
     }
 
 }