0

I'm using priority job queue in an project which uses the concepts of clean architecture. The thing is: to do DI with priority job queue I need to create a BaseJob job like this:

abstract public class BaseJob extends Job {

  @Retention(RetentionPolicy.SOURCE)
  @IntDef({UI_HIGH, BACKGROUND})
  public @interface Priority {

 }

 public static final int UI_HIGH = 10;
 public static final int BACKGROUND = 1;

 public BaseJob(Params params) {
  super(params);
 }

 protected boolean shouldRetry(Throwable throwable) {
   return true;
 }

public void inject(ApplicationComponent appComponent) {

}

The problem is that in the lines:

public void inject(ApplicationComponent appComponent) {

}

I need to access ApplicationComponent which is in presentation's layer, but since my BaseJob is in data's layer I don't have access to it.

If I make data's layer know about presentation I will break the principles of clean architecture.

Does anyone have an idea how I could do that?

  • What are you doing with that appComponent? – Robert Moskal Mar 25 '17 at 16:45
  • Following this sample: [link](https://github.com/yigit/dev-summit-architecture-demo/blob/master/client/app/src/main/java/com/android/example/devsummit/archdemo/di/module/ApplicationModule.java). I'm using it to inject dependencies in my job. I couldn't place to code here, so it's in line 111 – user2601142 Mar 25 '17 at 16:53

1 Answers1

0

In Uncle Bob's clean architecture there is no data layer but entities, use cases, interface adapters and frameworks. Inner circles must not know about outer circles. You can invert dependencies by defining an interface in an inner circle and implement it in an outer circle.

So probably u require an interface for ur ApplicationComponent to be defined in the inner circle.

For a more detailed discussion on dependency inversion have a look at my post https://plainionist.github.io/Implementing-Clean-Architecture-Controller-Presenter/

plainionist
  • 2,950
  • 1
  • 15
  • 27