Skip to content

feroznz/java-dependency-injection-using-Google-Guice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

java-dependency-injection-using-Google-Guice

Working with frameworks like spring in java we take the dependency injection for granted but what if we are not using any framework and have to manage the dependency injection ourselves!.

Google Guice to the rescue!

Google Guice: https://github.com/google/guice

DI using Guice in 3 steps:

  1. Define binding
    @Override
    protected void configure() {
        bind(Order.class).to(OrderImpl.class);
    }
}
  1. User @Inject annotation on the service constructor
 @Inject
 public OrderService(Order order) {
     this.order = order;
 }
  1. Build object using injector
Injector injector = Guice.createInjector(new OrderModule());
OrderService orderService = injector.getInstance(OrderService.class);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages