Slide 1

Slide 1 text

Modularity & Dependency Injection at Scale FOSS Asia 2020

Slide 2

Slide 2 text

@mrmans0n Nacho López Software Engineer Android Foundation Architecture @CesarDielo César Puerta Technical Lead Twitter for Android @bidyut Saud Khan Software Engineer Android Performance

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Author: Ben Sandofsky Date: Mon Jun 21 23:24:55 2010 -0700 Initial import.

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Periscope @PeriscopeCo You might have heard some news: It involves a blue bird. #YouCanGuessTheRest #WeJoinedTheFlockInJanuary 13 Mar 2015 629 761

Slide 11

Slide 11 text

+

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

D D

Slide 15

Slide 15 text

DI is important

Slide 16

Slide 16 text

DI is important Refactoring for… Correctness Testability Reusability

Slide 17

Slide 17 text

regardless of project size DI is important

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Static checks Errors at compile time > Runtime errors

Slide 20

Slide 20 text

Description: [Dagger/MissingBinding] com.twitter.ui.util.UiArchLayoutContentViewProvider cannot be provided without an @Inject constructor or an @Provides-annotated method. Description: [Dagger/DuplicateBindings] com.twitter.ui.util.UiArchLayoutContentViewProvider is bound multiple times.

Slide 21

Slide 21 text

Code generation Automating the creation of glue code

Slide 22

Slide 22 text

val inflater = LayoutInflater.from(context) val renderer = Renderer(inflater) val database = Database() val timeline = Timeline(database, renderer) class Renderer (database: Database, renderer: Renderer) class Timeline class Database() (inflater: LayoutInflater)

Slide 23

Slide 23 text

class Renderer (database: Database, renderer: Renderer) class Timeline class Database () (inflater: LayoutInflater) @Inject constructor @Inject constructor @Inject constructor

Slide 24

Slide 24 text

Graph Architecture Scoped object graphs mapping to the app lifecycle @Component @Subcomponent

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

@ApplicationScope @UserScope @RetainedScope @ViewScope

Slide 30

Slide 30 text

@Component(modules = [ApplicationModule::class]) @ApplicationScope interface ApplicationObjectGraph { fun userObjectGraphBuilder(): UserObjectGraph.Builder }

Slide 31

Slide 31 text

{ fun featureRetainedBuilder(): FeatureRetainedObjectGraph.Builder } @Subcomponent(modules = [UserModule::class]) @UserScope interface UserObjectGraph @Component(modules = [ApplicationModule::class]) @ApplicationScope interface ApplicationObjectGraph { fun userObjectGraphBuilder(): UserObjectGraph.Builder }

Slide 32

Slide 32 text

{ fun featureRetainedBuilder(): FeatureRetainedObjectGraph.Builder } @Subcomponent(modules = [UserModule::class]) @UserScope interface UserObjectGraph @ApplicationScope interface ApplicationObjectGraph { fun userObjectGraphBuilder(): UserObjectGraph.Builder } @Subcomponent(modules = [FeatureRetainedModule::class]) @RetainedScope interface FeatureRetainedObjectGraph { fun featureViewGraphBuilder(): FeatureViewObjectGraph.Builder }

Slide 33

Slide 33 text

{ fun featureRetainedBuilder(): FeatureRetainedObjectGraph.Builder } @UserScope interface UserObjectGraph @Subcomponent(modules = [FeatureRetainedModule::class]) @RetainedScope interface FeatureRetainedObjectGraph { fun featureViewGraphBuilder(): FeatureViewObjectGraph.Builder } @Subcomponent(modules = [FeatureViewModule::class]) @ViewScope interface FeatureViewObjectGraph

Slide 34

Slide 34 text

{ fun featureRetainedBuilder(): FeatureRetainedObjectGraph.Builder } @UserScope interface UserObjectGraph Components or ? Subcomponents @ApplicationScope @UserScope @RetainedScope @ViewScope

Slide 35

Slide 35 text

Components for the root graph for the nested graphs Subcomponents @ApplicationScope @UserScope @RetainedScope @ViewScope

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

How to instantiate your graphs?

Slide 38

Slide 38 text

component = .application(this) .build() class MyApplication : Application { private lateinit var component: ApplicationObjectGraph override fun onCreate() { } super.onCreate() } DaggerApplicationObjectGraph.builder()

Slide 39

Slide 39 text

Dagger.getObjectGraphBuilder() component = .application(this) .build() class MyApplication : Application { private lateinit var component: ApplicationObjectGraph override fun onCreate() { } super.onCreate() }

Slide 40

Slide 40 text

fun getObjectGraphBuilder(builderClass: Class): B } } class Dagger { companion object { inline fun getObjectGraphBuilder(): B = getObjectGraphBuilder(B::class.java) } {

Slide 41

Slide 41 text

if (!builderClass.isAnnotationPresent(Component.Builder::class.java)) { throw IllegalArgumentException("Not a component builder class: $builderClass") } val componentClass = builderClass.enclosingClass ?: throw IllegalStateException("Component builder is not enclosed in a component.") val generatedDaggerClassName = getDaggerComponentImplementationClassName(componentClass) val generatedObjectGraphClass = ReflectionUtils.loadClass(generatedDaggerClassName) ?: throw IllegalStateException("Generated Dagger class can't be found: $generatedDagge val builderMethod = ReflectionUtils.getMethod(generatedObjectGraphClass, "builder") ?: throw IllegalStateException("The Dagger component generated class does not contain return ReflectionUtils.invokeMethod(builderMethod, null) ?: throw IllegalStateException("The builder() method returned null.") fun getObjectGraphBuilder(builderClass: Class): B } } class Dagger { companion object { inline fun getObjectGraphBuilder(): B = getObjectGraphBuilder(B::class.java) } TL;DR Use reflection once to find and instantiate the graph’s Component.Builder {

Slide 42

Slide 42 text

if (!builderClass.isAnnotationPresent(Component.Builder::class.java)) { throw IllegalArgumentException("Not a component builder class: $builderClass") } val componentClass = builderClass.enclosingClass ?: throw IllegalStateException("Component builder is not enclosed in a component.") val generatedDaggerClassName = getDaggerComponentImplementationClassName(componentClass) val generatedObjectGraphClass = ReflectionUtils.loadClass(generatedDaggerClassName) ?: throw IllegalStateException("Generated Dagger class can't be found: $generatedDagge val builderMethod = ReflectionUtils.getMethod(generatedObjectGraphClass, "builder") ?: throw IllegalStateException("The Dagger component generated class does not contain return ReflectionUtils.invokeMethod(builderMethod, null) ?: throw IllegalStateException("The builder() method returned null.") fun getObjectGraphBuilder(builderClass: Class): B } } class Dagger { companion object { inline fun getObjectGraphBuilder(): B = getObjectGraphBuilder(B::class.java) } Don’t worry! We will share the code in GitHub! {

Slide 43

Slide 43 text

if (!builderClass.isAnnotationPresent(Component.Builder::class.java)) { throw IllegalArgumentException("Not a component builder class: $builderClass") } val componentClass = builderClass.enclosingClass ?: throw IllegalStateException("Component builder is not enclosed in a component.") val generatedDaggerClassName = getDaggerComponentImplementationClassName(componentClass) val generatedObjectGraphClass = ReflectionUtils.loadClass(generatedDaggerClassName) ?: throw IllegalStateException("Generated Dagger class can't be found: $generatedDagge val builderMethod = ReflectionUtils.getMethod(generatedObjectGraphClass, "builder") ?: throw IllegalStateException("The Dagger component generated class does not contain return ReflectionUtils.invokeMethod(builderMethod, null) ?: throw IllegalStateException("The builder() method returned null.") fun getObjectGraphBuilder(builderClass: Class): B } } class Dagger { companion object { inline fun getObjectGraphBuilder(): B = getObjectGraphBuilder(B::class.java) } Follow Us! github.com/twitter {

Slide 44

Slide 44 text

Referencing generated code Use reflection once to grab the root object graph builder. Dagger.getObjectGraphBuilder() DaggerApplicationObjectGraph.builder()

Slide 45

Slide 45 text

Where do we place our graphs?

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

@ApplicationScope @UserScope @RetainedScope @ViewScope

Slide 48

Slide 48 text

Let’s compose a Tweet

Slide 49

Slide 49 text

:features:composer ComposerActivity ComposerViewModel ComposerViewDelegate @RetainedScope @ViewScope @ApplicationScope @UserScope

Slide 50

Slide 50 text

:subsystems:tweets TweetRepository :features:composer @RetainedScope @ViewScope @ApplicationScope @UserScope

Slide 51

Slide 51 text

:subsystems:tweets TweetRepository :features:composer @RetainedScope @ViewScope @ApplicationScope @UserScope

Slide 52

Slide 52 text

:twitter:media ImageUploader :features:composer :subsystems:tweets @RetainedScope @ViewScope @UserScope @ApplicationScope

Slide 53

Slide 53 text

:twitter:media ImageUploader :features:composer :subsystems:tweets @RetainedScope @ViewScope @ApplicationScope @UserScope

Slide 54

Slide 54 text

:core:network OkHttpClient :features:composer :subsystems:tweets :twitter:media @RetainedScope @ViewScope @UserScope @ApplicationScope

Slide 55

Slide 55 text

:core:network :features:composer :subsystems:tweets :twitter:media @RetainedScope @ViewScope @ApplicationScope @UserScope ComposerNotifHandler

Slide 56

Slide 56 text

:core:network :features:composer :subsystems:tweets :twitter:media @RetainedScope @ViewScope @ApplicationScope @UserScope M M M M M M

Slide 57

Slide 57 text

:core:network :features:composer :subsystems:tweets :twitter:media @RetainedScope @ViewScope @ApplicationScope @UserScope M M M M M M

Slide 58

Slide 58 text

App wide graphs definitions belong in the top gradle module. Ideal Location

Slide 59

Slide 59 text

How to access graphs at the top from intermediate layers?

Slide 60

Slide 60 text

:twitter:media L ImageUploader LegacyActivity ApplicationObjectGraph

Slide 61

Slide 61 text

:twitter:media MediaAppSubgraph L LegacyActivity ApplicationObjectGraph

Slide 62

Slide 62 text

object ApplicationObjectGraphProvider { var graphProvider: Any? }

Slide 63

Slide 63 text

component = Dagger.getObjectGraphBuilder() .application(this) .build() class MyApplication : Application { private lateinit var component: ApplicationObjectGraph override fun onCreate() { } super.onCreate() }

Slide 64

Slide 64 text

super.onCreate() } ApplicationObjectGraphProvider.graphProvider = Dagger.getObjectGraphBuilder() .application(this) .build() class MyApplication : Application { override fun onCreate() { }

Slide 65

Slide 65 text

ApplicationObjectGraph ApplicationObjectGraphProvider :twitter:media L ImageUploader LegacyActivity MediaAppSubgraph

Slide 66

Slide 66 text

(ApplicationObjectGraphProvider.graphProvider as MediaAppSubgraph).imageUploader()

Slide 67

Slide 67 text

object ApplicationObjectGraphProvider { } fun getSubgraph(clazz: Class): T var graphProvider: Any? { return clazz.cast(graphProvider) }

Slide 68

Slide 68 text

fun imageUploader(): ImageUploader interface MediaAppSubgraph { } companion object { fun get(): MediaAppSubgraph { return ApplicationObjectGraphProvider.graphProvider .getSubgraph(MediaAppSubgraph::class.java) }

Slide 69

Slide 69 text

val uploader = MediaAppSubgraph.get().imageUploader() fun imageUploader(): ImageUploader interface MediaAppSubgraph { } companion object { fun get(): MediaAppSubgraph { return ApplicationObjectGraphProvider.graphProvider .getSubgraph(MediaAppSubgraph::class.java) }

Slide 70

Slide 70 text

val uploader = MediaAppSubgraph.get().imageUploader()

Slide 71

Slide 71 text

Grabbing objects from Dagger w/o visibility Wrap your Application and User graphs in providers that can be statically obtained, and add a way to extract subgraphs from them. ApplicationObjectGraphProvider UserObjectGraphProvider MediaAppSubgraph L LegacyActivity

Slide 72

Slide 72 text

Graphs can be large!

Slide 73

Slide 73 text

fun okHttpClient(): OkHttpClient fun twitterApiService(): TwitterApiService @Component @ApplicationScope interface ApplicationObjectGraph fun composerLauncher(): ComposerLauncher fun composerNotificationHandler(): ComposerNotifHandler fun tweetsRepository(): TweetsRepository fun tweetsDataSource(): TweetsDataSource fun imageLoader(): ImageLoader { fun loginController(): LoginController fun loginAssistController(): LoginAssistController fun appEventTracker(): AppEventTracker fun installationReferrer(): InstallationReferrer fun jobManager(): JobManager fun playServicesUtil(): PlayServicesUtil fun httpRequestController(): HttpRequestController fun registrableHeadsetPlugReceiver(): RegistrableHeadsetPlugReceiver , TweetRepositoryAppModule::cl (modules = [ComposerAppModule::class

Slide 74

Slide 74 text

fun okHttpClient(): OkHttpClient fun twitterApiService(): TwitterApiService @Component @ApplicationScope interface ApplicationObjectGraph fun composerLauncher(): ComposerLauncher fun composerNotificationHandler(): ComposerNotifHandler fun tweetsRepository(): TweetsRepository fun tweetsDataSource(): TweetsDataSource fun imageLoader(): ImageLoader { fun loginController(): LoginController fun loginAssistController(): LoginAssistController fun appEventTracker(): AppEventTracker fun installationReferrer(): InstallationReferrer fun jobManager(): JobManager fun playServicesUtil(): PlayServicesUtil fun httpRequestController(): HttpRequestController fun registrableHeadsetPlugReceiver(): RegistrableHeadsetPlugReceiver , TweetRepositoryAppModule::cl (modules = [ComposerAppModule::class

Slide 75

Slide 75 text

Subgraphs Slices of an Object Graph

Slide 76

Slide 76 text

@Component @ApplicationScope interface ApplicationObjectGraph { } fun okHttpClient(): OkHttpClient fun twitterApiService(): TwitterApiService fun composerLauncher(): ComposerLauncher fun composerNotificationHandler(): ComposerNotifHandler fun tweetsRepository(): TweetsRepository fun tweetsDataSource(): TweetsDataSource fun imageLoader(): ImageLoader :app:twitter

Slide 77

Slide 77 text

: @Component @ApplicationScope interface ApplicationObjectGraph { } fun okHttpClient(): OkHttpClient fun twitterApiService(): TwitterApiService fun composerLauncher(): ComposerLauncher fun composerNotificationHandler(): ComposerNotifHandler fun tweetsRepository(): TweetsRepository fun tweetsDataSource(): TweetsDataSource fun imageLoader(): ImageLoader ComposerAppSubgraph interface ComposerAppSubgraph { } :app:twitter :features:composer

Slide 78

Slide 78 text

@Component @ApplicationScope interface ApplicationObjectGraph , : { } fun okHttpClient(): OkHttpClient fun twitterApiService(): TwitterApiService fun tweetsRepository(): TweetsRepository fun tweetsDataSource(): TweetsDataSource fun imageLoader(): ImageLoader ComposerAppSubgraph interface TweetRepositoryAppSubgraph { } TweetRepositoryAppSubgraph :app:twitter :subsystems:tweets

Slide 79

Slide 79 text

@Component @ApplicationScope interface ApplicationObjectGraph , : { } fun okHttpClient(): OkHttpClient fun twitterApiService(): TwitterApiService fun imageLoader(): ImageLoader ComposerAppSubgraph TweetRepositoryAppSubgraph interface MediaAppSubgraph { } MediaAppSubgraph , :app:twitter :twitter:media

Slide 80

Slide 80 text

@Component @ApplicationScope interface ApplicationObjectGraph , : fun okHttpClient(): OkHttpClient fun twitterApiService(): TwitterApiService ComposerAppSubgraph TweetRepositoryAppSubgraph MediaAppSubgraph , interface CoreNetworkAppSubgraph { } CoreNetworkAppSubgraph , :core:network :app:twitter

Slide 81

Slide 81 text

:core:network :features:composer :subsystems:tweets :twitter:media TweetRepositoryAppSubgraph MediaAppSubgraph CoreNetworkAppSubgraph ApplicationObjectGraph ComposerAppSubgraph

Slide 82

Slide 82 text

:core:network :features:composer :subsystems:tweets :twitter:media TweetRepositoryAppSubgraph MediaAppSubgraph CoreNetworkAppSubgraph ApplicationObjectGraph ComposerAppSubgraph

Slide 83

Slide 83 text

Big monolithic graphs Scatter the definitions of the object graphs into subgraphs that can live in the gradle modules where the bindings are actually defined.

Slide 84

Slide 84 text

How would that work in testing?

Slide 85

Slide 85 text

object ApplicationObjectGraphProvider { } var graphProvider: Any? private val mapping: Map, Any> = mutableMapOf() fun overrideSubgraph(clazz: Class, subgraph: T) { mapping[clazz] = subgraph } fun getSubgraph(clazz: Class): T { if (mapping.containsKey(clazz)) return clazz.cast(mapping[clazz]) return clazz.cast(graphProvider) }

Slide 86

Slide 86 text

object ApplicationObjectGraphProvider { } var graphProvider: Any? private val mapping: Map, Any> = mutableMapOf() fun overrideSubgraph(clazz: Class, subgraph: T) { mapping[clazz] = subgraph } fun getSubgraph(clazz: Class): T { if (mapping.containsKey(clazz)) return clazz.cast(mapping[clazz]) return clazz.cast(graphProvider) }

Slide 87

Slide 87 text

How to decouple features? The app navigation case

Slide 88

Slide 88 text

ComposerActivity MainActivity DMActivity TweetDetailActivity C D M TD

Slide 89

Slide 89 text

ComposerActivity MainActivity DMActivity TweetDetailActivity C D M TD Circular Dependency!

Slide 90

Slide 90 text

ComposerActivity MainActivity TweetDetailActivity C D M TD DMActivity :subsystems:navigation Intent factories ActivityArgs TD C D M

Slide 91

Slide 91 text

ComposerActivity MainActivity TweetDetailActivity C D M TD DMActivity :subsystems:navigation TD M D C ActivityArgs

Slide 92

Slide 92 text

interface ActivityArgs { fun toIntent(context: Context, clazz: Class): Intent }

Slide 93

Slide 93 text

override fun toIntent(context: Context, clazz: Class): { .apply { putExtra("user_id", uid) putExtra("text", text) } } interface ActivityArgs { fun toIntent(context: Context, clazz: Class): Intent } data class ComposerArgs(val uid: Long, val text: String): ActivityArgs { } return Intent(context, clazz)

Slide 94

Slide 94 text

Service Discovery Multibindings

Slide 95

Slide 95 text

C D TD ComposerArgs TweetDetailArgs DMArgs :features:tweetdetail :features:dm :features:composer @Multibinds

Slide 96

Slide 96 text

C D TD ComposerArgs TweetDetailArgs DMArgs :features:tweetdetail :features:dm :features:composer @Multibinds

Slide 97

Slide 97 text

C D TD ComposerArgs TweetDetailArgs DMArgs :features:tweetdetail :features:dm :features:composer Map, Class> C D TD ComposerActivity DMActivity TweetDetailActivity

Slide 98

Slide 98 text

@Module object ComposerModule { @Provides @ApplicationScope fun provideActivityClass: Class { } } :features:composer @ActivityArgsKey(ComposerArgs::class) @IntoMap return ComposerActivity::class.java

Slide 99

Slide 99 text

@ApplicationScope class ActivityStarter @Inject constructor( ) private val activityMap: Map, Class>

Slide 100

Slide 100 text

{ fun startActivity(context: Context, args: ActivityArgs) { } } @ApplicationScope class ActivityStarter @Inject constructor( ) val intent = args.toIntent(context, activityMap[args.javaClass]) context.startActivity(intent) private val activityMap: Map, Class>

Slide 101

Slide 101 text

C D TD C D TD Start an Activity we can’t see at compile time At compile time you might not see everything, but at runtime it is all there. Let’s use Multibindings to aggregate references at compile time and resolve them at runtime.

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

Initializers Notification Handlers Deeplink Handlers

Slide 104

Slide 104 text

No content

Slide 105

Slide 105 text

Subgraphs are not atomic units

Slide 106

Slide 106 text

S ApplicationObjectGraph M S M S M S M S M S M S M S M

Slide 107

Slide 107 text

S ApplicationObjectGraph M S M S M S M S S M S M S M @Component(modules = [ ComposerAppModule::class, TweetDetailAppModule::class, HomeAppModule::class, ExploreAppModule::class, CoreAppModule::class, CoreNetworkAppModule::class, MediaAppModule::class, VideoAppModule::class, NavigationAppModule::class, LoggingAppModule::class, TimelineAppModule::class, … and on and on and on ]) @ApplicationScope interface ApplicationObjectGraph: M

Slide 108

Slide 108 text

ApplicationObjectGraph M M M M M M M M TimelineAppModule::class, … and on and on and on ]) @ApplicationScope interface ApplicationObjectGraph: InitializationSubgraph, ComposerAppSubgraph, TweetDetailAppSubgraph, HomeAppSubgraph, ExploreAppSubgraph, CoreAppSubgraph, CoreNetworkAppSubgraph, MediaAppSubgraph, VideoAppSubgraph, NavigationAppSubgraph, … and on and on and on S S S S S S S S

Slide 109

Slide 109 text

@Component(modules = [ BroadcastAppModule::class, … and on and on and on ]) @ApplicationScope interface ApplicationObjectGraph: InitializationSubgraph, BroadcastAppSubgraph, TweetDetailAppSubgraph, @Component(modules = [ BroadcastAppModule::class, … and on and on and on ]) @ApplicationScope interface ApplicationObjectGraph: InitializationSubgraph, BroadcastAppSubgraph, MapSubgraph, S M

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

{ fun broadcastController(): BroadcastController } @Module { @Binds @ApplicationScope fun bindBcastController(impl: BroadcastControllerImpl): BroadcastController } object BroadcastAppModule interface BroadcastAppSubgraph

Slide 112

Slide 112 text

@ApplicationScope interface BroadcastAppSubgraph { fun broadcastController(): BroadcastController } @Subgraph @Subgraph(modules = [BroadcastAppModule::class]) @Module { @Binds @ApplicationScope fun bindBcastController(impl: BroadcastControllerImpl): BroadcastController } object BroadcastAppModule interface BroadcastAppSubgraph

Slide 113

Slide 113 text

@ApplicationScope interface ApplicationObjectGraph : BroadcastAppSubgraph, InitializationSubgraph, ... (modules = [BroadcastAppModule::class, ...]) @Component

Slide 114

Slide 114 text

@ApplicationScope interface ApplicationObjectGraph : BroadcastAppSubgraph, InitializationSubgraph, ... @ObjectGraph

Slide 115

Slide 115 text

@UserScope interface UserObjectGraph : UserManagerSubgraph, TweetRepository, ... (modules = [UserManagerModule::class, ...]) @ApplicationScope interface ApplicationObjectGraph : BroadcastAppSubgraph, InitializationSubgraph, ... @ObjectGraph @Subcomponent

Slide 116

Slide 116 text

@UserScope interface UserObjectGraph : UserManagerSubgraph, TweetRepository, ... @ApplicationScope interface ApplicationObjectGraph : BroadcastAppSubgraph, InitializationSubgraph, ... @ObjectGraph @ObjectGraph

Slide 117

Slide 117 text

Annotation Processor @ObjectGraph @Subgraph @Component @Subcomponent

Slide 118

Slide 118 text

@ObjectGraph @Subgraph Annotation Processor @Component @Subcomponent

Slide 119

Slide 119 text

Annotation Processor @ObjectGraph @Subgraph @Component @Subcomponent

Slide 120

Slide 120 text

Fully Dagger Compatible Annotation Processor

Slide 121

Slide 121 text

Subgraphs are not encapsulated

Slide 122

Slide 122 text

S S S S S S

Slide 123

Slide 123 text

S S S S S S

Slide 124

Slide 124 text

S @ApplicationScope interface BroadcastAppSubgraph { fun broadcastController(): BroadcastController } @Subgraph(modules = [BroadcastAppModule::class])

Slide 125

Slide 125 text

@Subgraph( subgraphDependencies = [ CoreNetworkSubgraph::class, VideoPlayerSubgraph::class ]) S @ApplicationScope interface BroadcastAppSubgraph { fun broadcastController(): BroadcastController } @Subgraph @Subgraph(modules = [BroadcastAppModule::class],

Slide 126

Slide 126 text

S ApplicationObjectGraph S S S S S S S

Slide 127

Slide 127 text

S ApplicationObjectGraph S S S S S S S

Slide 128

Slide 128 text

S ApplicationObjectGraph S S S S S S S S

Slide 129

Slide 129 text

Subgraphs don’t support inversion of dependencies

Slide 130

Slide 130 text

interface DatabaseSubgraph { fun migrationManager(): MigrationManager } fun schema(): Schema @Subgraph

Slide 131

Slide 131 text

interface DatabaseSubgraph { fun migrationManager(): MigrationManager } fun schema(): Schema @Subgraph @Abstract @Abstract @Subgraph interface TwitterDatabaseSubgraph : DatabaseSubgraph { @Binds fun schema(bound: TwitterSchema): Schema }

Slide 132

Slide 132 text

Graphs are hard to maintain

Slide 133

Slide 133 text

@ObjectGraph @ApplicationScope interface ApplicationObjectGraph: InitializationSubgraph, BroadcastAppSubgraph, TweetDetailAppSubgraph, HomeAppSubgraph, ExploreAppSubgraph, CoreAppSubgraph, CoreNetworkAppSubgraph, MediaAppSubgraph, VideoPlayerSubgraph, NavigationAppSubgraph, TweetUploadAppSubgraph, PerformanceMetricsAppSubgraph, DMAppSubgraph, JSONModelsAppSubgraph, DynamicModulesAppSubgraph, NotificationsAppSubgraph, This is actually insane

Slide 134

Slide 134 text

Annotation Processor @ObjectGraph @ApplicationScope interface ApplicationObjectGraph: InitializationSubgraph, BroadcastAppSubgraph, TweetDetailAppSubgraph, HomeAppSubgraph, ExploreAppSubgraph, CoreAppSubgraph, CoreNetworkAppSubgraph, MediaAppSubgraph, VideoPlayerSubgraph, NavigationAppSubgraph, TweetUploadAppSubgraph, PerformanceMetricsAppSubgraph, DMAppSubgraph, JSONModelsAppSubgraph, DynamicModulesAppSubgraph, NotificationsAppSubgraph,

Slide 135

Slide 135 text

@ObjectGraph @ApplicationScope interface ApplicationObjectGraph Annotation Processor Automatic Discovery

Slide 136

Slide 136 text

S ApplicationObjectGraph S S S S S S S

Slide 137

Slide 137 text

And more!

Slide 138

Slide 138 text

Annotation Processor

Slide 139

Slide 139 text

Scythe OOP concepts for DI IDE support Better build times Binding overrides Modular scalability Self documentation Reusability Automatic discovery Completeness validation Factory bindings Assisted Injection Compatible with Dagger

Slide 140

Slide 140 text

Scythe Open-source launch for everybody in 2020

Slide 141

Slide 141 text

@mrmans0n Nacho @CesarDielo César @bidyut Saud Thank you! More questions? Follow ups from this talk? Hit us up on Twitter!