我有一个简单的服务:

public class AccountService implements IAccountService {

    @Inject
    IAccountDAO accountDAO;

}


此类由我的模块提供:

@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();
    }

}


有没有办法让匕首在返回“服务”之后并在注入其他对象之前对“服务”进行注入?

最佳答案

好的,它比我想像的要容易(并且实际上是作为示例显示在匕首主页中的):

@Module(library = true )
public class ServiceModule {
    @Provides @Singleton
    IAccountService provideAccountStoreService(AccountService service) {
        return service;
    }

    @Provides @Singleton
    IAccountDAO accountDAO provideAccountDAO() {
        return new AccountDAO();
    }

}

07-26 06:23