View Javadoc

1   /*
2    * $Id: ConfigServiceModule.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.module.guice;
11  
12  import org.mule.api.transformer.Transformer;
13  import org.mule.tck.testmodels.fruit.BananaFactory;
14  import org.mule.tck.testmodels.mule.TestAgent;
15  
16  import com.google.inject.AbstractModule;
17  import com.google.inject.Provides;
18  import com.google.inject.name.Named;
19  
20  /**
21   * Simple Guice module that binds a service interface
22   */
23  public class ConfigServiceModule extends AbstractModule
24  {
25      protected void configure()
26      {
27          //Our auto transform service component
28          this.bind(AutoTransformServiceInterface.class).to(DefaultAutoTransformService.class);
29  
30          //Injection service component
31          this.bind(BananaServiceInterface.class).to(BananaInjectionService.class);
32  
33          //Will make the transformer available in Mule
34          //this.bind(Transformer.class).to(OrangetoAppleTransformer.class);
35  
36      }
37  
38      //This automatically binds the intance to the return type
39      @Provides
40      BananaFactory provideBananaFactory()
41      {
42          return new BananaFactory();
43      }
44  
45      @Provides
46      TestAgent provideTestAgent()
47      {
48          return new TestAgent();
49      }
50  
51      @Provides @Named("orange-to-apple")
52      Transformer providesOrangetoAppleTransformer()
53      {
54          return new OrangetoAppleTransformer();
55      }
56  }