Guice provider bindings example

Guice provider bindings example

If you are using Google Guice framework for dependency injection in your application you could use provider interface, which has method to supplying its values. In this demo you will see how to use Guice provider interface to get an object of implementing class at run time, call its method which return string to and print its value on the console:

  • Provider interface:

  • HelloGuiceService interface:

  • HelloGuiceServiceImpl.java:

  • HelloGuiceServiceProvider.java:

  • HelloGuiceModule.java: It’s module class where you define binding of the class. Below it says interface HelloGuiceService provider class is HelloGuiceServiceProvider which return object of HelloGuiceServiceImpl class. In Singleton.class means it’s behavior is singleton where it will return only one instance of the class:

  • ProviderServiceMainClass.java is java main class to test our implementation and print message on the console:

Guice provider bindings example

  • For more information please visit Guice documentation here

download  Download project:  GoogleGuiceProvider

Leave a Reply

Your email address will not be published. Required fields are marked *