Bind(Handler.class) .annotatedWith(Names.named("something")) .to(SomeImplementation.class);
Will translate to
@Module public class SomethingModule { @Provides @Named("something")
What would be related to the " Injector " (component):
@Component(modules={SomethingModule.class}) //scope if needed public interface SomethingComponent { @Named("something") Handler handler(); void inject(ThatThingy thatThingy); }
What is the โinjector" that you must create using the created APT creator:
SomethingComponent somethingComponent = DaggerSomethingComponent.builder() .somethingModule(new SomethingModule()) //can be omitted, has no params .build(); somethingComponent.inject(thatThingy);
Where is this thing
public class ThatThingy { @Inject @Named("something") Handler handler; }
Components usually exist for an area , so, for example, @ApplicationScope has one โinjectorโ (component). Examination can be achieved using subcomponents and component dependencies.
An important fact is that the component has rendering methods (which are dependencies that are inherited from undermining components if you use component dependencies) and void inject(X x); formatted methods. This is required for field injection for a particular type . For example, a base class can introduce itself and not subclasses. However, you can write a method called protected abstract void injectThis() , which also calls .inject(this) in a subclass.
Like I really haven't used Guice, I'm not sure I missed anything. I think I forgot the injection constructor, which is a problem because when the Dagger supports it, it cannot be reconfigured. For reconfiguration, you need to use modules and make injections in the constructors yourself.
@Module(includes={ThoseModule.class, TheseModule.class}) public class SomethingModule { @Provides @Singleton public Whatever whatever(Those those, These these) { return new Whatever(those, these); } } public class Whatever { Those those; These these; public Whatever(Those those, These these) { this.those = those; this.these = these; } } @Component(modules={SomethingModule.class}) @Singleton public interface SomethingComponent { These these(); Those those(); Whatever whatever(); }