feat: use inject container
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
17269b50f4
commit
e68005fd6f
@ -18,7 +18,7 @@ export namespace plugin {
|
|||||||
*/
|
*/
|
||||||
export interface PluginManager {
|
export interface PluginManager {
|
||||||
scan(folder: string): void;
|
scan(folder: string): void;
|
||||||
build(container: Container): void;
|
build(): void;
|
||||||
load(...args: any[]): void;
|
load(...args: any[]): void;
|
||||||
enable(...args: any[]): void;
|
enable(...args: any[]): void;
|
||||||
disable(...args: any[]): void;
|
disable(...args: any[]): void;
|
||||||
|
@ -2,7 +2,7 @@ import { interfaces, Container } from "inversify";
|
|||||||
|
|
||||||
let _container: Container;
|
let _container: Container;
|
||||||
|
|
||||||
const CONTAINER = Symbol.for("@ms/ioc:Container");
|
const ContainerInstance = Symbol.for("@ms/ioc:Container");
|
||||||
const INJECTION = Symbol.for("INJECTION");
|
const INJECTION = Symbol.for("INJECTION");
|
||||||
|
|
||||||
function _proxyGetter(
|
function _proxyGetter(
|
||||||
@ -35,12 +35,12 @@ function _proxyGetter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initContainer(container: Container) {
|
function initContainer(container: Container) {
|
||||||
Reflect.defineMetadata(CONTAINER, container, Reflect);
|
Reflect.defineMetadata(ContainerInstance, container, Reflect);
|
||||||
_container = container;
|
_container = container;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getContainer(): Container {
|
function getContainer(): Container {
|
||||||
return _container || Reflect.getMetadata(CONTAINER, Reflect)
|
return _container || Reflect.getMetadata(ContainerInstance, Reflect)
|
||||||
}
|
}
|
||||||
|
|
||||||
function makePropertyInjectDecorator(doCache: boolean) {
|
function makePropertyInjectDecorator(doCache: boolean) {
|
||||||
@ -97,6 +97,7 @@ let lazyMultiInject = makePropertyMultiInjectDecorator(doCache)
|
|||||||
export {
|
export {
|
||||||
initContainer,
|
initContainer,
|
||||||
getContainer,
|
getContainer,
|
||||||
|
ContainerInstance,
|
||||||
lazyInject,
|
lazyInject,
|
||||||
lazyInjectNamed,
|
lazyInjectNamed,
|
||||||
lazyInjectTagged,
|
lazyInjectTagged,
|
||||||
|
@ -3,7 +3,7 @@ import '@ms/nashorn'
|
|||||||
import { plugin, server, task, MiaoScriptConsole } from '@ms/api'
|
import { plugin, server, task, MiaoScriptConsole } from '@ms/api'
|
||||||
import { PluginManagerImpl } from '@ms/plugin'
|
import { PluginManagerImpl } from '@ms/plugin'
|
||||||
import { XMLHttpRequest as xhr } from '@ms/ployfill'
|
import { XMLHttpRequest as xhr } from '@ms/ployfill'
|
||||||
import { DefaultContainer as container, injectable, inject, postConstruct } from '@ms/container'
|
import { DefaultContainer as container, injectable, inject, ContainerInstance } from '@ms/container'
|
||||||
|
|
||||||
let startTime = new Date().getTime();
|
let startTime = new Date().getTime();
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class MiaoScriptCore {
|
|||||||
|
|
||||||
loadPlugins() {
|
loadPlugins() {
|
||||||
this.pluginManager.scan('plugins');
|
this.pluginManager.scan('plugins');
|
||||||
this.pluginManager.build(container);
|
this.pluginManager.build();
|
||||||
this.pluginManager.load();
|
this.pluginManager.load();
|
||||||
this.pluginManager.enable();
|
this.pluginManager.enable();
|
||||||
}
|
}
|
||||||
@ -75,6 +75,7 @@ function detectServer(){
|
|||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
console.info('Initialization MiaoScript Core Package @ms/core. Please wait...')
|
console.info('Initialization MiaoScript Core Package @ms/core. Please wait...')
|
||||||
|
container.bind(ContainerInstance).toConstantValue(container);
|
||||||
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance());
|
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance());
|
||||||
let type = detectServer();
|
let type = detectServer();
|
||||||
require(`@ms/${type}`);
|
require(`@ms/${type}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user