Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dagger 2 Static Injections

Any example of Dagger 2 static injections. I have already tried this : -

class A{
 @Inject
 static B b;

 static {
  getAppInstance().getComponent().inject(A.class);
 }

 static anyMethod(){
  b.anotherMethod();  
 }
}

public interface AppComponent{
 void inject(Class<A> aClass);
}
like image 521
aprofromindia Avatar asked Oct 30 '22 11:10

aprofromindia


1 Answers

So this is my proposed answer: -

class A{
 private static B b = getAppInstance.getComponent().getB();

 static anyMethod(){
  b.anotherMethod();  
 }
}

public interface AppComponent{
 B getB();
}
like image 136
aprofromindia Avatar answered Nov 09 '22 05:11

aprofromindia