Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyApplication {
- private MessageService service;
- @Inject
- public void setService(MessageService svc){
- this.service=svc;
- }
- }
- class AppInjector extends AbstractModule {
- @Override
- protected void configure() {
- bind(MessageService.class).to(EmailService.class);
- }
- }
- public class ClientApplication {
- public static void main(String[] args) {
- Injector injector = Guice.createInjector(new AppInjector());
- MyApplication app = injector.getInstance(MyApplication.class);
- app.sendMessage(); // how does injection work here if there is no call of app.setService() ?
- // is this a correct way to change binding during a runtime? i guess no ;/
- app.setService(new AnotherService());
- app.sendMessage();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement