Begin abstracting global container into injector
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {Application} from './Application'
|
||||
import {Container, DependencyKey} from '../di'
|
||||
import {Container, DependencyKey, Injectable} from '../di'
|
||||
|
||||
/**
|
||||
* Base type for a class that supports binding methods by string.
|
||||
@@ -25,12 +25,11 @@ export function isBindable(what: unknown): what is Bindable {
|
||||
/**
|
||||
* Base for classes that gives access to the global application and container.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AppClass {
|
||||
/** The global application instance. */
|
||||
private readonly appClassApplication!: Application;
|
||||
|
||||
constructor() {
|
||||
this.appClassApplication = Application.getApplication()
|
||||
private get appClassApplication(): Application {
|
||||
return Application.getApplication()
|
||||
}
|
||||
|
||||
/** Get the global Application. */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Container} from '../di'
|
||||
import {Container, ContainerBlueprint} from '../di'
|
||||
import {
|
||||
ErrorWithContext,
|
||||
globalRegistry,
|
||||
@@ -52,6 +52,11 @@ export class Application extends Container {
|
||||
const existing = <Container | undefined> globalRegistry.getGlobal('extollo/injector')
|
||||
if ( !existing ) {
|
||||
const container = new Application()
|
||||
|
||||
ContainerBlueprint.getContainerBlueprint()
|
||||
.resolve()
|
||||
.map(factory => container.registerFactory(factory))
|
||||
|
||||
globalRegistry.setGlobal('extollo/injector', container)
|
||||
return container
|
||||
}
|
||||
@@ -74,6 +79,11 @@ export class Application extends Container {
|
||||
return app
|
||||
} else {
|
||||
const app = new Application()
|
||||
|
||||
ContainerBlueprint.getContainerBlueprint()
|
||||
.resolve()
|
||||
.map(factory => app.registerFactory(factory))
|
||||
|
||||
globalRegistry.setGlobal('extollo/injector', app)
|
||||
return app
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user