15 lines
358 B
JavaScript
15 lines
358 B
JavaScript
export default class Container {
|
|
constructor() {
|
|
this.services = new Map();
|
|
}
|
|
register(name, factory) {
|
|
this.services.set(name, factory);
|
|
}
|
|
resolve(name) {
|
|
const factory = this.services.get(name);
|
|
if (!factory)
|
|
throw new Error(`Service "${name}" not found.`);
|
|
return factory();
|
|
}
|
|
}
|