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.
Trying to inject dependencies from dynamic feature modules
- Loading branch information
1 parent
baef2e6
commit a3c35f3
Showing
15 changed files
with
210 additions
and
26 deletions.
There are no files selected for viewing
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
56 changes: 56 additions & 0 deletions
56
core/src/main/java/io/plaidapp/core/interfaces/SearchDataSourceFactoriesRegistry.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,56 @@ | ||
/* | ||
* Copyright 2019 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.interfaces | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
|
||
private const val designerNewsSearchDataSourceFactoryProviderClassName = | ||
"io.plaidapp.designernews.domain.search.DesignerNewsSearchFactoryProvider" | ||
|
||
// TODO add dribbble as well | ||
private val factoryClassNames = | ||
listOf(designerNewsSearchDataSourceFactoryProviderClassName) | ||
|
||
class SearchDataSourceFactoriesRegistry { | ||
|
||
private val _dataSourceFactories = | ||
MutableLiveData<List<SearchDataSourceFactory>>(getAlreadyAvailableDataSourceFactories()) | ||
|
||
val dataSourceFactories: LiveData<List<SearchDataSourceFactory>> | ||
get() = _dataSourceFactories | ||
|
||
fun add(dataSourceFactory: SearchDataSourceFactory) { | ||
val existingDataSources = _dataSourceFactories.value.orEmpty().toMutableList() | ||
existingDataSources.add(dataSourceFactory) | ||
_dataSourceFactories.postValue(existingDataSources) | ||
} | ||
|
||
fun remove(dataSourceFactory: SearchDataSourceFactory) { | ||
val existingDataSources = _dataSourceFactories.value.orEmpty().toMutableList() | ||
existingDataSources.remove(dataSourceFactory) | ||
_dataSourceFactories.postValue(existingDataSources) | ||
} | ||
|
||
private fun getAlreadyAvailableDataSourceFactories(): List<SearchDataSourceFactory> { | ||
return factoryClassNames.map { | ||
val clazz = Class.forName(it) | ||
val instance = clazz.newInstance() as SearchFactoryProvider | ||
instance.getFactory() | ||
} | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
core/src/main/java/io/plaidapp/core/interfaces/SearchFactoryProvider.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 2019 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.interfaces | ||
|
||
interface SearchFactoryProvider { | ||
|
||
fun getFactory(): SearchDataSourceFactory | ||
} |
24 changes: 24 additions & 0 deletions
24
designernews/src/main/java/io/plaidapp/designernews/dagger/DesignerNewsSearchComponent.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,24 @@ | ||
/* | ||
* Copyright 2019 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.designernews.dagger | ||
|
||
import dagger.Component | ||
|
||
@Component( | ||
modules = [SearchDataModule::class] | ||
) | ||
interface DesignerNewsSearchComponent |
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
38 changes: 38 additions & 0 deletions
38
designernews/src/main/java/io/plaidapp/designernews/dagger/SearchDataModule.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,38 @@ | ||
/* | ||
* Copyright 2019 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.designernews.dagger | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import io.plaidapp.core.dagger.DataSourcesModule | ||
import io.plaidapp.core.designernews.data.stories.StoriesRepository | ||
import io.plaidapp.core.interfaces.SearchDataSourceFactoriesRegistry | ||
import io.plaidapp.designernews.domain.search.DesignerNewsSearchDataSourceFactory | ||
|
||
@Module(includes = [DataSourcesModule::class]) | ||
class SearchDataModule { | ||
|
||
@Provides | ||
fun designerNewsSearchDataSourceFactory( | ||
repository: StoriesRepository, | ||
registry: SearchDataSourceFactoriesRegistry | ||
): DesignerNewsSearchDataSourceFactory { | ||
val factory = DesignerNewsSearchDataSourceFactory(repository) | ||
registry.add(factory) | ||
return factory | ||
} | ||
} |
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
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
37 changes: 37 additions & 0 deletions
37
...src/main/java/io/plaidapp/designernews/domain/search/DesignerNewsSearchFactoryProvider.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 2019 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.designernews.domain.search | ||
|
||
import io.plaidapp.core.designernews.data.stories.StoriesRepository | ||
import io.plaidapp.core.interfaces.SearchDataSourceFactory | ||
import io.plaidapp.core.interfaces.SearchFactoryProvider | ||
import io.plaidapp.designernews.dagger.inject | ||
import javax.inject.Inject | ||
|
||
class DesignerNewsSearchFactoryProvider : SearchFactoryProvider { | ||
|
||
init { | ||
inject() | ||
} | ||
|
||
@Inject | ||
lateinit var repository: StoriesRepository | ||
|
||
override fun getFactory(): SearchDataSourceFactory { | ||
return DesignerNewsSearchDataSourceFactory(repository) | ||
} | ||
} |
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
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
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
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
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