Home | History | Annotate | Download | only in example
      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 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;
     20 
     21 import com.google.inject.Guice;
     22 import com.google.inject.Injector;
     23 import com.google.inject.Singleton;
     24 import com.google.inject.servlet.GuiceServletContextListener;
     25 import com.google.inject.servlet.ServletModule;
     26 import com.google.inject.struts2.Struts2GuicePluginModule;
     27 
     28 /**
     29  * Example application module.
     30  *
     31  * @author crazybob (at) google.com (Bob Lee)
     32  */
     33 public class ExampleListener extends GuiceServletContextListener {
     34 
     35   public Injector getInjector() {
     36     return Guice.createInjector(
     37       new Struts2GuicePluginModule(),
     38       new ServletModule() {
     39         @Override
     40         protected void configureServlets() {
     41           // Struts 2 setup
     42           bind(StrutsPrepareAndExecuteFilter.class).in(Singleton.class);
     43           filter("/*").through(StrutsPrepareAndExecuteFilter.class);
     44 
     45           // Our app-specific code
     46           bind(Service.class).to(ServiceImpl.class);
     47       }
     48     });
     49   }
     50 
     51 }
     52