Modules - VladimirRopotan/DInjector GitHub Wiki
Modules are used to define a list of provides that you want to use in your application
To define a module, need to implement the InjectorModule protocol
class MyModule: InjectorModule {
...
}
It describes all the provide that are related to this module.
class MyModule: InjectorModule {
@Provide
var first = { _ in First() }
@Provide
var second = { _ in Second() }
}
for Injector to use the module, need to declare it in the setup method
var injector: Injector = Injector.setup(modules: MyModule())
Multiple modules can be used to separate into logical components
class FirstModule: InjectorModule {
...
}
class SecondModule: InjectorModule {
...
}
Then the setup method looks like this
var injector: Injector = Injector.setup(modules: FirstModule(), SecondModule())