Dagger 2 Static Injection

Any example of static dagger injections 2. I 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); } 
+5
source share
1 answer

So this is my suggested answer: -

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

 public interface AppComponent{ B getB(); } 
+2
source

Source: https://habr.com/ru/post/1241040/


All Articles