-
-
Save ypcode/a361ac11129f3661e56a144a109bf31b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class DependenciesManager { | |
private serviceScope: ServiceScope; | |
public configure( | |
rootServiceScope: ServiceScope, | |
serviceScopeConfiguration: (rootServiceScope: ServiceScope) => Promise<ServiceScope> | |
): Promise<any> { | |
return new Promise((resolve, reject) => { | |
serviceScopeConfiguration(rootServiceScope) | |
.then((usedScope) => { | |
this.serviceScope = usedScope; | |
resolve(); | |
}) | |
.catch((error) => { | |
reject(error); | |
}); | |
}); | |
} | |
public inject<TService>(serviceKey: ServiceKey<TService>): TService { | |
if (this.serviceScope) { | |
return this.serviceScope.consume(serviceKey); | |
} else { | |
return null; | |
} | |
} | |
} | |
const Dependencies: DependenciesManager = new DependenciesManager(); | |
export default Dependencies; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment