Это должно быть в вашем классе приложения. Внутри onCreate ()

у сделать DI из некоторого класса для использования в приложении, таких какRetrofit, Picasso, они могут нормально работать, когда я использую их в Activity, но когда я пытаюсь использовать некоторый DI в другом классе, я получаю NULL, например, этот код работает нормально

public class ActivityRegister extends BaseActivities {

    @Inject
    GithubService githubService;

    @Inject
    JobManager jobManager;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        ...
        repositoryCall = githubService.getAllRepositories();
        ...
}

private void getRepositories() {
    repositoryCall.enqueue(new Callback<List<GithubRepo>>() {
        @Override
        public void onResponse(Call<List<GithubRepo>> call, Response<List<GithubRepo>> response) {
            List<GithubRepo> repoList = new ArrayList<>();
            repoList.addAll(response.body());
            Log.e("JOB ", "OK");
        }

        @Override
        public void onFailure(Call<List<GithubRepo>> call, Throwable t) {
            Log.e("JOB ", "NO!!");
        }
    });
}

заGithubService я успешно создал экземпляр, а не пытаюсь использовать это вGetLatestRepositoriesно я получаюNULLКак я могу правильно определить, что вводить в класс?

public class GetLatestRepositories extends Job {
    @Inject
    GithubService githubService;

    private Call<List<GithubRepo>> repositoryCall;

    public GetLatestRepositories() {
        super(new Params(Priority.MID).requireNetwork().persist());
        repositoryCall = githubService.getAllRepositories();
    }

    @Override
    public void onAdded() {

    }

    @Override
    public void onRun() throws Throwable {
        repositoryCall.enqueue(new Callback<List<GithubRepo>>() {
            @Override
            public void onResponse(Call<List<GithubRepo>> call, Response<List<GithubRepo>> response) {
                List<GithubRepo> repoList = new ArrayList<>();
                repoList.addAll(response.body());
                Log.e("JOB ", "OK");
            }
            @Override
            public void onFailure(Call<List<GithubRepo>> call, Throwable t) {
                Log.e("JOB ", "NO!!");
            }
        });
    }
    @Override
    protected void onCancel(int cancelReason, @Nullable Throwable throwable) {

    }

    @Override
    protected RetryConstraint shouldReRunOnThrowable(@NonNull Throwable throwable, int runCount, int maxRunCount) {
        return null;
    }
}

ActivityRegisterComponent класс компонента:

@ActivityRegisterScope
@Component(modules = ActivityRegisterModule.class, dependencies = GithubApplicationComponent.class)
public interface ActivityRegisterComponent {

    void injectActivityRegister(ActivityRegister homeActivity);
}

GithubApplicationComponent:

@GithubApplicationScope
@Component(modules = {GithubServiceModule.class, PicassoModule.class, JobManagerModule.class, ActivityModule.class})
public interface GithubApplicationComponent {

    Picasso getPicasso();

    GithubService getGithubService();

    JobManager getJobManager();
}

Класс приложения:

public class Alachiq extends Application {

    ...
    public static  Alachiq                    alachiq;
    public static  String                     packageName;
    public static  Resources                  resources;

    private static Context                    context;

    private        GithubService              githubService;
    private        Picasso                    picasso;
    private        GithubApplicationComponent component;
    private        JobManager                 jobManager;
    private static Alachiq                    instance;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        //@formatter:off
            resources   = this.getResources();
            context     = getApplicationContext();
            packageName = getPackageName();
        //@formatter:on


        Timber.plant(new Timber.DebugTree());

        component = DaggerGithubApplicationComponent.builder()
                .contextModule(new ContextModule(this))
                .build();

        githubService = component.getGithubService();
        picasso = component.getPicasso();
        jobManager = component.getJobManager();
    }

    public GithubApplicationComponent component() {
        return component;
    }

    public static Alachiq get(Activity activity) {
        return (Alachiq) activity.getApplication();
    }

    public static Alachiq getInstance() {
        return instance;
    }

    public static Context getContext() {
        return context;
    }
}

и ActivityRegisteronCreate:

ApplicationComponent component = DaggerApplicationComponent.builder()
                .githubApplicationComponent(Alachiq.get(this).component())
                .build();

GithubService учебный класс:

public interface GithubService {

    @GET("users/{username}/repos")
    Call<List<GithubRepo>> getReposForUser(@Path("username") String username);

    @GET("repositories")
    Call<List<GithubRepo>> getAllRepositories();

    @GET("users/{username}")
    Call<GithubUser> getUser(@Path("username") String username);
}

Ответы на вопрос(1)

Ваш ответ на вопрос