Skip to content

Latest commit

 

History

History
137 lines (103 loc) · 4.1 KB

README.md

File metadata and controls

137 lines (103 loc) · 4.1 KB

[WIP] Sealant

GitHub release License

Sealant creates Dagger bindings and integrations for Android classes using the Anvil. This is meant to be an alternative to Hilt, for those who'd prefer to enjoy the faster compilation and better flexibility of Anvil.

Since Sealant is an extension upon Anvil, its code generation will be applied to Kotlin files only.

Inspired by: Marcello Galhardo article N26 Path to Anvil, Zac Sweers article Extending Anvil for Fun and Profit and Rick Busarow library Tangle

Setup

Add dependencies:

dependencies {
    def sealant_version = "0.3.1"

    // Common
    implementation "io.github.steinerok.sealant:di-common:${sealant_version}"
    // Core
    implementation "io.github.steinerok.sealant:sealant-core-api:${sealant_version}"
    anvil "io.github.steinerok.sealant:sealant-core-codegen:${sealant_version}"
    // Appcomponent
    implementation "io.github.steinerok.sealant:sealant-appcomponent-api:${sealant_version}"
    anvil "io.github.steinerok.sealant:sealant-appcomponent-codegen:${sealant_version}"
    // Fragment
    implementation "io.github.steinerok.sealant:sealant-fragment-api:${sealant_version}"
    anvil "io.github.steinerok.sealant:sealant-fragment-codegen:${sealant_version}"
    // ViewModel
    implementation "io.github.steinerok.sealant:sealant-viewmodel-api:${sealant_version}"
    anvil "io.github.steinerok.sealant:sealant-viewmodel-codegen:${sealant_version}"
    // WorkManager
    implementation "io.github.steinerok.sealant:sealant-work-api:${sealant_version}"
    anvil "io.github.steinerok.sealant:sealant-work-codegen:${sealant_version}"
}

Make sure that you have mavenCentral() in the list of repositories:

repositories {
    mavenCentral()
}

Features

Core

@SealantConfiguration(
    addAppcomponentSupport = true,
    addViewModelSupport = true,
    addFragmentSupport = true,
    addWorkSupport = true,
)
abstract class AppScope private constructor()

Appcomponent

@InjectWith(AppScope::class)
class MainActivity : ComponentActivity() {
    /* Your dependencies, inject via lateinit var and @Inject annotation */
}

Fragment

@ContributesFragment(scope = AppScope::class)
class MainFragment @Inject constructor(
    /* Your dependencies */
) : Fragment()

ViewModel

@ContributesViewModel(AppScope::class)
class MainViewModel @Inject constructor(
    private val application: Application,
    private val ssHandle: SavedStateHandle,
    /* Your dependencies */
) : ViewModel()

Work

@ContributesWorker(AppScope::class)
class MainWorker2 @AssistedInject constructor(
    @Assisted appContext: Context,
    @Assisted params: WorkerParameters,
    /* Your dependencies */
) : CoroutineWorker(appContext, params)

Contributions

Please contribute! I will gladly review any pull requests. Make sure to read the Contributing page first though.

License

Copyright (c) 2022-2023 Ihor Kushnirenko

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.