Last active
November 29, 2024 09:31
-
-
Save murki/7c99e2d011c663deb25267e5462cc02d to your computer and use it in GitHub Desktop.
Revisions
-
murki revised this gist
Jun 1, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,6 @@ class PlacesActivity : AppCompatActivity() { super.onCreate(savedInstanceState) // This is how you instantiate your Presenter while the service locator resolves all of its dependencies // Note that the explicit type argument <PlacesPresenter> is not even necessary since Kotlin can infer the type placesPresenter = application.getSystemService<PlacesPresenter>() } } -
murki revised this gist
Jun 1, 2018 . No changes.There are no files selected for viewing
-
murki revised this gist
May 16, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ class PlacesActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // This is how you instantiate your Presenter while the service locator resolves all of its dependencies // Note that the explicit type argument <PlacesPresenter> is not even necessary since Kotlin can infer the type placesPresenter = placesPresenter = application.getSystemService<PlacesPresenter>() } } -
murki revised this gist
May 16, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ class ServiceLocatorApplication : Application() { override fun getSystemService(name: String?): Any { // All this logic can be extracted into a separate "Module" class return when (name) { // We use the full class' name as the key PlacesPresenter::class.java.name -> PlacesPresenter(getSystemService<ILocationRepository>(), getSystemService<IPlacesRepository>()) ILocationRepository::class.java.name -> GmsLocationRepository(getSystemService<FusedLocationProviderClient>()) IPlacesRepository::class.java.name -> GmsPlacesRepository(getSystemService<GeoDataClient>()) @@ -20,5 +21,6 @@ class ServiceLocatorApplication : Application() { * Generic strongly-typed extension method for injection */ inline fun <reified T : Any> Application.getSystemService() : T { // We extract the class name from the generic type return this.getSystemService(T::class.java.name) as T } -
murki revised this gist
May 16, 2018 . 2 changed files with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ class PlacesActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // This is how you instantiate your Presenter while the service locator resolves all of its dependencies placesPresenter = placesPresenter = application.getSystemService<PlacesPresenter>() } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,16 @@ class ServiceLocatorApplication : Application() { /** * Dependency injection using service locator pattern */ override fun getSystemService(name: String?): Any { // All this logic can be extracted into a separate "Module" class return when (name) { PlacesPresenter::class.java.name -> PlacesPresenter(getSystemService<ILocationRepository>(), getSystemService<IPlacesRepository>()) ILocationRepository::class.java.name -> GmsLocationRepository(getSystemService<FusedLocationProviderClient>()) IPlacesRepository::class.java.name -> GmsPlacesRepository(getSystemService<GeoDataClient>()) FusedLocationProviderClient::class.java.name -> LocationServices.getFusedLocationProviderClient(this) GeoDataClient::class.java.name -> Places.getGeoDataClient(this, null) else -> super.getSystemService(name) } } -
murki created this gist
May 16, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ class PlacesActivity : AppCompatActivity() { private lateinit var placesPresenter: PlacesPresenter override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // This is how you locate your Presenter placesPresenter = placesPresenter = application.getSystemService<PlacesPresenter>() } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ class CityGuideApp : Application() { /** * Dependency injection using service locator pattern */ override fun getSystemService(name: String?): Any { // All this logic can be extracted into its own "module" return when (name) { FusedLocationProviderClient::class.java.name -> LocationServices.getFusedLocationProviderClient(this) GeoDataClient::class.java.name -> Places.getGeoDataClient(this, null) ILocationRepository::class.java.name -> GmsLocationRepository(getSystemService<FusedLocationProviderClient>()) IPlacesRepository::class.java.name -> GmsPlacesRepository(getSystemService<GeoDataClient>()) PlacesPresenter::class.java.name -> PlacesPresenter(getSystemService<ILocationRepository>(), getSystemService<IPlacesRepository>()) else -> super.getSystemService(name) } } } /** * Generic strongly-typed extension method for injection */ inline fun <reified T : Any> Application.getSystemService() : T { return this.getSystemService(T::class.java.name) as T }