Add ModuleContainer and convenient named factory constructor for Injector to address the problem of injecting classes from one module into a class from another module. As you can see implementation is simple and straightforward, it also doesn't break existing API. It works for our team, hope you will find it useful.
Example:
// Library package.
class DefaultProductService implements ProductService {}
class LibraryModule extends Module {
configure() {
bind(ProductService).toType(DefaultProductService);
}
}
// Main application package.
class CatalogPage {
@inject ProductService productService; // Class from Library module.
}
class AppModule extends Module {
configure() {
bind(CatalogPage).toType(CatalogPage);
}
}
// Usage in the main app
main () {
Injector injector = new Injector.fromModules([new LibraryModule(), new AppModule()]);
var catalogPage = injector.getInstance(CatalogPage);
}
Add
ModuleContainer
and convenient named factory constructor forInjector
to address the problem of injecting classes from one module into a class from another module. As you can see implementation is simple and straightforward, it also doesn't break existing API. It works for our team, hope you will find it useful.Example: