Skip to content

Instantly share code, notes, and snippets.

View wadva474's full-sized avatar

MUSA ABDUL-WADUD wadva474

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