1 /* 2 * Copyright (C) 2006 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.inject.struts2.example; 18 19 import com.google.inject.Guice; 20 import com.google.inject.Injector; 21 import com.google.inject.Singleton; 22 import com.google.inject.servlet.GuiceServletContextListener; 23 import com.google.inject.servlet.ServletModule; 24 import com.google.inject.struts2.Struts2GuicePluginModule; 25 import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter; 26 27 /** 28 * Example application module. 29 * 30 * @author crazybob@google.com (Bob Lee) 31 */ 32 public class ExampleListener extends GuiceServletContextListener { 33 getInjector()34 public Injector getInjector() { 35 return Guice.createInjector( 36 new Struts2GuicePluginModule(), 37 new ServletModule() { 38 @Override 39 protected void configureServlets() { 40 // Struts 2 setup 41 bind(StrutsPrepareAndExecuteFilter.class).in(Singleton.class); 42 filter("/*").through(StrutsPrepareAndExecuteFilter.class); 43 44 // Our app-specific code 45 bind(Service.class).to(ServiceImpl.class); 46 } 47 }); 48 } 49 } 50