Ich habe einen einfachen Service:
public class AccountService implements IAccountService {
@Inject
IAccountDAO accountDAO;
}
Diese Klasse wird von meinem Modul bereitgestellt:
@Module(library = true )
public class ServiceModule {
@Provides @Singleton
IAccountService provideAccountStoreService(IAccountDAO accountDAO) {
IAccountService service= new AccountService();
//Somehow set the accountDAO inside service
return service;
}
@Provides @Singleton
IAccountDAO accountDAO provideAccountDAO() {
return new AccountDAO();
}
}
Gibt es eine Möglichkeit, Dolch bei "Service" zu injizieren, nachdem ich es zurückgegeben habe und bevor es in ein anderes Objekt injiziert wurde?
Antworten:
1 für die Antwort № 1Ok, es war einfacher als ich dachte (und tatsächlich als Beispiel auf der Dolch-Homepage gezeigt):
@Module(library = true )
public class ServiceModule {
@Provides @Singleton
IAccountService provideAccountStoreService(AccountService service) {
return service;
}
@Provides @Singleton
IAccountDAO accountDAO provideAccountDAO() {
return new AccountDAO();
}
}