InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
9.09k stars 719 forks source link

could not find Fragment constructor after change behaviour #1606

Open jonrysimbolon opened 1 year ago

jonrysimbolon commented 1 year ago

Describe the bug while i change my mode from dark to light or vice versa, i got this error: "could not find Fragment constructor"

To Reproduce i have followed this docs fragment-factory and every things is good (i don't use the koin scope cause error, and the error is required Scoped? and not LifecycleCoroutineScope) after i change my mode from dark to light or vice versa, i found the error.

This is my implementation

MyApplication.kt

startKoin { androidLogger() androidContext(this@MyApplication) fragmentFactory() modules( module ) }

AppModule.kt

val module = module { single { RequestOptions() } single { StoryAdapter(get()) } fragment{ HomeFragment(get()) } }

MainActivity.kt

override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setupKoinFragmentFactory() setContentView(viewBinding.root) }

HomeFragment.kt

class HomeFragment( private val storyAdapter: StoryAdapter, ) : Fragment() { //.. }

Expected behavior this is work

Koin project used and used version (please complete the following information): implementation 'io.insert-koin:koin-core:3.4.2' implementation 'io.insert-koin:koin-core-coroutines:3.4.1' implementation 'io.insert-koin:koin-test:3.4.1' implementation 'io.insert-koin:koin-android:3.4.2' implementation 'io.insert-koin:koin-androidx-navigation:3.4.2'

Additional moduleDefinition This is my first time to open the open source issue, so give me criticism and suggestions that improve my questions for additional: i use navigation component in this project and i use HomeFragment as startDestination i open this cause i have been around on google and chat-gpt, and i didn't find the solution. much obliged

arnaudgiuliani commented 1 year ago

Hello, thanks for your feedback. I need to see from where it fails exactly, Koin or Android.

I would need a small sample project to help reproduce. Could you make it?

jonrysimbolon commented 1 year ago

sorry too long sir, this is my sample project https://github.com/jonrysimbolon/TestingApps/tree/test2 i want use dependency on my fragment but require fragment if initialize outside constructor -> success, but i want use inside constructor of homefragment if there're wrong word and deeds, i apologize

arnaudgiuliani commented 1 year ago

In your case, you can't inject the fragment's constructor with injected parameters. The property works because you can specify the injected Activity.