forked from nickbutcher/plaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce multiple dagger components and modules
This started off as a quick way to adding dagger to :dribbble but then got a little out of hand due to dependencies into :core and :app, especially within DataManager. Also there are still issues with application wide singletons.
- Loading branch information
1 parent
3a78172
commit d15117d
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
core/src/main/java/io/plaidapp/core/dagger/DataManagerComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2018 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.plaidapp.core.dagger | ||
|
||
import dagger.Component | ||
|
||
@Component(modules = [DataManagerModule::class]) | ||
interface DataManagerComponent |
29 changes: 29 additions & 0 deletions
29
core/src/main/java/io/plaidapp/core/dagger/DribbbleDataModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2018 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.plaidapp.core.dagger | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import io.plaidapp.core.dribbble.data.search.DribbbleSearchService | ||
import retrofit2.Retrofit | ||
|
||
@Module(includes = [DribbbleRetrofitModule::class]) | ||
class DribbbleDataModule { | ||
|
||
@Provides fun provideDribbbleSearchService(retrofit: Retrofit): DribbbleSearchService = | ||
retrofit.create(DribbbleSearchService::class.java) | ||
} |
44 changes: 44 additions & 0 deletions
44
core/src/main/java/io/plaidapp/core/dagger/DribbbleRetrofitModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2018 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.plaidapp.core.dagger | ||
|
||
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.experimental.CoroutineCallAdapterFactory | ||
import dagger.Module | ||
import dagger.Provides | ||
import io.plaidapp.core.dribbble.data.search.DribbbleSearchConverter | ||
import io.plaidapp.core.dribbble.data.search.DribbbleSearchService | ||
import io.plaidapp.core.loggingInterceptor | ||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
|
||
/** | ||
* Module to set up retrofit. | ||
*/ | ||
@Module | ||
class DribbbleRetrofitModule { | ||
|
||
@Provides fun provideOkHttpClient(): OkHttpClient = | ||
OkHttpClient.Builder().addInterceptor(loggingInterceptor).build() | ||
|
||
@Provides fun provideRetrofitInterface(client: OkHttpClient): Retrofit = | ||
Retrofit.Builder() | ||
.baseUrl(DribbbleSearchService.ENDPOINT) | ||
.addConverterFactory(DribbbleSearchConverter.Factory()) | ||
.addCallAdapterFactory(CoroutineCallAdapterFactory()) | ||
.client(client) | ||
.build() | ||
} |
29 changes: 29 additions & 0 deletions
29
core/src/main/java/io/plaidapp/core/dagger/DribbleSearchServiceProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2018 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.plaidapp.core.dagger | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import io.plaidapp.core.dribbble.data.search.DribbbleSearchService | ||
import io.plaidapp.core.dribbble.data.search.SearchRemoteDataSource | ||
|
||
@Module(includes = [DribbbleDataModule::class]) | ||
class DribbleSearchServiceProvider { | ||
|
||
@Provides fun provideDribbbleSearchService(dribbbleSearchService: DribbbleSearchService) = | ||
SearchRemoteDataSource.getInstance(dribbbleSearchService) | ||
} |
37 changes: 37 additions & 0 deletions
37
core/src/main/java/io/plaidapp/core/dagger/ShotsRepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2018 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.plaidapp.core.dagger | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import io.plaidapp.core.data.CoroutinesContextProvider | ||
import io.plaidapp.core.dribbble.data.ShotsRepository | ||
import io.plaidapp.core.dribbble.data.search.SearchRemoteDataSource | ||
|
||
/** | ||
* Provide [ShotsRepository]. | ||
* | ||
* TODO: make this an app wide singleton. | ||
*/ | ||
@Module(includes = [CoroutinesContextProviderModule::class, DribbleSearchServiceProvider::class]) | ||
class ShotsRepositoryModule { | ||
|
||
@Provides fun provideShotsRepository( | ||
remoteDataSource: SearchRemoteDataSource, | ||
contextProvider: CoroutinesContextProvider | ||
) = ShotsRepository.getInstance(remoteDataSource, contextProvider) | ||
} |