inversio-loader
Convention based initialization of inversio containers.
Load components and dependencies from file structure using file patterns, single file components and modules.
API
cwd (current working directory) denotes root folder for searches.
filter should either be a
- predicate as in
path -> boolean
- string (glob) that will be converted to a minimatch predicate.
new Loader({pattern?})
Construct new loader instance. If pattern is specified, it will be passed as default to discover({cwd, pattern})
.
create({pattern?}) -> Loader
Shorthand for creating Loader instance.
const loader = create let continer = await
.use(module) -> Loader
Allow module to register. Module should be a
{ // loader.discover(...) // loader.use(...) // loader.component(...) }
or
{ ... }
.use(...modules) -> Loader
Register multiple modules.
.discover({cwd, pattern}) -> Loader
pattern defaults to pattern specified in constructor. cwd is root folder for single file component search.
Single file components should be like
moduleexports container
container is an inversio container instance.
.component({name, factory, depends?, tags?, order?, ...}) -> Loader
Shorthand for registering a component the inversio way.
.component(...components) -> Loader
Register multiple components.
.load() -> Promise(container)
Return inversio container with all components registered.
Example:
// ./app/foo.comp.js// single file component 'foo'moduleexports container // ./modules/module-x.js// module referring to multiple components in modules/**/*.comp.jsmodule loader // index.jsvar Loader = let container = await // resolve componentlet foo = await container // -> instance of Bar