Skip to content

Instantly share code, notes, and snippets.

@ypcode
Last active Jul 29, 2018
Embed
What would you like to do?
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