Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Koin with feature layer SDK #1969

Open
yoobi opened this issue Sep 8, 2024 · 0 comments
Open

Koin with feature layer SDK #1969

yoobi opened this issue Sep 8, 2024 · 0 comments

Comments

@yoobi
Copy link

yoobi commented Sep 8, 2024

Hello,

I'm building up a custom SDK with Koin with the following architectures where data -> domain <- ui

features/
├─ feature-a/
│  ├─ data/
│  ├─ domain/
│  ├─ ui/
├─ injector

In :feature-a:data

val exampleADataModule = module {
    singleOf<ExampleAGreetings>(::ExampleAGreetingsImpl)
}

class ExampleAGreetingsImpl: ExampleAGreetings {
    override fun getGreetings(): String = "Hello world"
}

In :feature-a:domain

interface ExampleAGreetings {
    fun getGreetings(): String
}

class GetGreetingsUseCase(private val exampleAGreetings: ExampleAGreetings) {
    operator fun invoke() = exampleAGreetings.getGreetings()
}

In :feature-a:ui which implements :injector

internal val exampleABModule = module {
    factory {
        GetGreetingsUseCase(get())
    }
}

class ExampleAFragment: Fragment(R.layout.fragment_example_a), CustomKoinComponent {
    private val useCase by inject<GetLoadHomeUseCase>()

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val tv = view.findViewById<TextView>(R.id.text)
        tv.text = useCase()
    }
}
interface CustomKoinComponent : KoinComponent {
    override fun getKoin(): Koin = AwesomeSdk.koin
}
object AwesomeSdk {
    private lateinit var appContext: Context
    val koin by lazy {
        koinApplication {
            androidContext(appContext)
        }.koin
    }

    @Synchronized
    fun init(context: Context) {
        appContext = context
    }
}

Do you have advice with this kind of architecture ? How can I tell koin to load the exampleADataModule while keeping this dependency rule data -> domain <- ui ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant