small and loose dependency injection library
$ npm i conr
import conr from 'conr';
type Container = {
foo: string;
bar: string;
name: (name: string) => string;
}
const instance = conr<Container>();
instance.init({
foo: 'Hello',
bar: 'World',
name: () => ``
});
instance.set('name', (name) => `My name is ${name}.`);
instance.resolve((foo, bar) => {
console.log(foo, bar); // Hello, World
});
instance.resolve(async function ({foo, name}) {
console.log(foo, name('John Doe')); // Hello, My name is John Doe.
console.log(this) // {fizz: "buzz"}
}, {fizz: "buzz"})
MIT License, see LICENSE