env-manage-plugin
Version:
A dev env plugin that integrates an Express server with request proxying capabilities.
42 lines (41 loc) • 1.66 kB
JavaScript
import { EnvController } from "./controllers/EnvController.js";
import { DevServerController } from "./controllers/DevServerController.js";
import { EnvRepo } from "./repositories/EnvRepo.js";
import { EnvService } from "./service/EnvService.js";
import { DevServerService } from "./service/DevServerService.js";
import { DevServerRepo } from "./repositories/DevServerRepo.js";
import { ProxyAutoStarter } from "./service/ProxyAutoStarterService.js";
class Container {
constructor() {
this.dependencies = new Map();
// 环境和服务的注册
const envRepo = new EnvRepo();
const devServerRepo = new DevServerRepo();
// configIns.initConfig();
this.register("envService", new EnvService(envRepo, devServerRepo));
this.register("envController", new EnvController(this.get("envService")));
// 开发服务器服务和控制器的注册
this.register("devServerService", new DevServerService(devServerRepo, envRepo));
this.register("devServerController", new DevServerController(this.get("devServerService")));
setTimeout(() => {
new ProxyAutoStarter(envRepo, this.get("envService"));
}, 5000);
}
static getInstance() {
if (!this.instance) {
this.instance = new Container();
}
return this.instance;
}
register(key, value) {
this.dependencies.set(key, value);
return this;
}
get(key) {
if (!this.dependencies.has(key)) {
throw new Error(`Dependency ${key} not found`);
}
return this.dependencies.get(key);
}
}
export { Container };