Skip to content

Use Generic an dagger_2  #13

@amin3536

Description

@amin3536

hello
how can i use Generic class like below? if use this cod can i call two different query same time? and how do i use injection for service ?

`
public class Service<T extends RealmObject & HasId> extends StoreService<T>{
    @Inject
    public Service(Class<T> clazz, ApiInterface apiInterface) {
       super(clazz, new Dao<T>(apiInterface));
        this.syncWith(new BaseRealmService<>(clazz));
   }

public static class Dao<T> extends StoreDao<T>{
    private final ApiInterface apiInterface;

    public Dao(ApiInterface apiInterface) {
        this.apiInterface = apiInterface;
    }

    @Override
    public Flowable<Optional<List<T>>> getAll(Filter filter, SortingMode sortingMode) {
        return super.getAll(filter, sortingMode);
    }
 }
 `

how can use dagger module for injection service?

           `@Module(includes = ApiModule.class)
            public class RepositoryModule<T> {

                @Provides
                 public Service serviceProvide(Class<T> tClass,ApiInterface apiInterface){
                     return new Service(tClass,apiInterface);
                 }

             }`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions