A minimal solution of dependency injection for projects that scale.
A minimal solution of dependency injection for projects that scale.
🙂
yarn add entrance-decorator
import {entrance} from 'entrance-decorator';
export class Entrances {
constructor(private url: string) {}
@entrance
get uiService() {
return new UIService(this.errorService);
}
@entrance
get errorService() {
return new ErrorService({
baseURL: this.url,
});
}
}
import {entrance} from 'entrance-decorator';
export class MobileEntrances extends Entrances {
// Extend entrance
@entrance
get mobileService() {
return new MobileService(this.errorService);
}
// Override entrance
@entrance
get uiService() {
return new MobileUIService(this.errorService);
}
}
const entrances = new Entrances('https://makeflow.com');
You may use the entrances
object in whatever way you want. For example, we use Context
in React (in a decorator manner) and use something like entrances.launchServer()
in server-side applications.
Cache and circular dependency check, nothing else.
MIT License.