dagger-2

Dagger2 Optimal way to inject dependencies from two different classes

和自甴很熟 提交于 2019-12-13 02:55:11
问题 After searching and trying too many things i'm stuck in some what seems like an easy problem. Below is my module which is reponsible for injecting retrofit. @Module public class NetworkingModule { @Provides public Retrofit providesRetrofit() { Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(Constants.BASE_URL) .addConverterFactory(GsonConverterFactory.create(gson)) .build(); return retrofit; }

Injecting a dependency with Dagger 2 only into one of the product flavors

邮差的信 提交于 2019-12-13 02:06:08
问题 My application consists of two product flavors: free and pro. I have an ApplicationModule that provides the object for ads, but this object is only required by the free version, as the pro version does not have the com.google.android.gms:play-services-ads:8.3.0 dependency. How do I structure my project such that only if the free product flavor is in use the ApplicationModule provides the ads object? 回答1: Since you have two product flavors, i am assuming the free version classes are in the

Swappable modules with Dagger 2

一笑奈何 提交于 2019-12-13 01:17:20
问题 So I have some code that runs an algorithm, say with an AlgoRunner class. Now this AlgoRunner class can be implemented in multiple ways to run different algorithms using Algo classes. I want to use Dagger 2 to provide different implementations of the AlgoRunner class to a "Manager" class that passes input to AlgoRunner as well as other components that it manages. Question I have the following right now, but I'm not sure if this is the correct way, mainly because of that empty

JSON data not showing in the Recylerview MVVM

南笙酒味 提交于 2019-12-13 01:16:05
问题 I'm trying to parse Json in Recyclerview using Data binding. When I run the app it's only showing blank screen with no error/crashes. Json data: { "msg":[ "football", "cricket", "baseball", "rugby", "gulf" ], "status":"success" } The Api interface SportsApi { /** * Get the Sports from the API */ @GET("/sports") fun getSports(): Observable<Sports> } The adaperclass: class PostListAdapter: RecyclerView.Adapter<PostListAdapter.ViewHolder>() { private lateinit var postList:Sports override fun

Dagger 2 does not inject my Object but can be obtained from component

谁说我不能喝 提交于 2019-12-12 18:33:40
问题 I have my component like @GithubListActivityScope @Component(modules = { GithubListActivityModule.class,GlideActivityModule.class }) public interface GithubListActivityComponent { GithubUserListAdapter githubUserListAdapter ( ); RequestManager requestManager(); LinearLayoutManager linearLayoutManager(); } And I have a module like this : @Module public class GithubListActivityModule { private final Activity githubListActivity; public GithubListActivityModule ( Activity activity ) { this

How to provide objects of the same type? Dagger2

北城余情 提交于 2019-12-12 18:26:13
问题 I am new at Dagger2 and tried to build such sample to understood how does it work. There is my sample code : MainActivity public class MainActivity extends AppCompatActivity { @Inject protected ApiInterface apiInterface; @Inject protected Integer valueInt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); App.getComponent().inject(this); } public void testButton(View view) { if (apiInterface == null ||

Dagger2 is not generating Dagger* classes

百般思念 提交于 2019-12-12 13:43:37
问题 As the title says, Dagger2 is not generating the Dagger* prefixed classes for my Android project. I looked at all other similar posts I could find but nothing helps. I'm trying to add it to an existing project, and I had some initial problems getting it to play nicely with data binding, but I seem to have sorted that out i.e. no compile errors on the data binding, and it generates code for it. I have also downloaded several example projects which work fine. My top level graddle file has

Dagger2 not generating Daggercomponent classes

强颜欢笑 提交于 2019-12-12 11:14:48
问题 Dagger2 is not generating any component classes in android studio i know its a known problem while i have gone through almost all ways to implement in my android studio and have tried on various tutorials but every time i got struck here, it fails to build the daggercomponent class . I have also tried to rebuild ,clean gradles and invalidate caches but it does not help . Here is my one of sample project build.gradle buildscript { repositories { jcenter() } dependencies { classpath 'com

Dagger 2: What does @Module(includes =) do?

折月煮酒 提交于 2019-12-12 10:30:25
问题 I'm working on a project and I'm trying to make it as modular as possible. I'm trying to use the @Module(includes = {}) annotation to achieve my goals, and it's not working too well. I have a gradle module for all my Java code and within that each section has a module (AboutModule for the About page dependencies, for example). Then, for the whole "Core" gradle module, I have one Dagger 2 module called "CoreModule" which looks like this: @Module(includes = { AddonModule.class, VersionModule

WorkManager Java Android Dagger2 [closed]

杀马特。学长 韩版系。学妹 提交于 2019-12-12 06:39:08
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 months ago . I NEED working Workmanager in Android app with JAVA only (without Kotlin!!!). In a project, we use just dagger2.8 (without android-dagger!) and I need to inject or access to some Injected classes like DataBase. (it injected in AppComponent). Already tried: https://proandroiddev.com/dagger-2-setup