This file contains 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 characters
//IOS Injecting NotesViewModel | |
final class NotesViewModelWrapper : ObservableObject{ | |
let notesViewModel : NotesViewModel = Koin.instance.get() | |
} |
This file contains 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 characters
//Android Injecting the NotesViewModel | |
@Composable | |
fun NotesScreen(notesViewModel: NotesViewModel = koinViewModel()) { | |
} |
This file contains 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 characters
@main | |
struct iOSApp: App { | |
init() { | |
Koin.start() | |
} | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
} | |
} |
This file contains 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 characters
import Foundation | |
import shared | |
final class Koin { | |
private var core: Koin_coreKoin? | |
static let instance = Koin() |
This file contains 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 characters
//In the IOS shared Module | |
object KoinIos { | |
fun initialize(): KoinApplication = initKoin( | |
appModule = module { | |
} | |
) | |
} | |
fun Koin.get(objCClass: ObjCClass): Any { | |
val klass = getOriginalKotlinClass(objCClass)!! |
This file contains 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 characters
class DiApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
initKoin( | |
appModule = module { | |
single { | |
this@DiApplication | |
} | |
}, | |
viewModelsModule = module { |
This file contains 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 characters
fun initKoin( | |
appModule: Module = module { }, | |
repositoriesModule: Module = Modules.repositories, | |
viewModelsModule: Module = Modules.viewModels, | |
): KoinApplication = startKoin { | |
modules( | |
appModule, | |
repositoriesModule, | |
viewModelsModule, | |
platformModule |
This file contains 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 characters
//Android module for SqlDriver | |
actual val platformModule: Module = module { | |
single { | |
AndroidSqliteDriver(NoteDatabase.Schema,get(),"NotesDb") | |
} | |
} | |
//Ios module for SqlDriver | |
actual val platformModule : Module = module { | |
single { |
This file contains 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 characters
object Modules { | |
val repositories = module{ | |
factory { NotesRepository(get()) } | |
} | |
val core = module { | |
factory { DatabaseHelper(get()) } | |
} | |
val viewModels = module { | |
factory { NotesViewModel(get()) } | |
} |
This file contains 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 characters
//Common Main Source | |
val commonMain by getting { | |
dependencies { | |
implementation(libs.koin) | |
} | |
} | |
// Common Test | |
val commonTest by getting { | |
dependencies { | |
implementation(kotlin(“test”)) |
NewerOlder