Skip to content

Instantly share code, notes, and snippets.

@ypcode
Last active July 29, 2018 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ypcode/a361ac11129f3661e56a144a109bf31b to your computer and use it in GitHub Desktop.
Save ypcode/a361ac11129f3661e56a144a109bf31b to your computer and use it in GitHub Desktop.
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