import { Container, interfaces } from 'inversify'; import { App } from './models/app'; import { DatasetManager } from './models/dataset-manager'; import { Canvas, CanvasConfig } from './models/canvas'; import { Component, ComponentConfig } from './models/component'; import { MODEL, FACTORY } from './constants'; const container = new Container({ skipBaseClassChecks: true }); container.bind(MODEL.App).to(App).inSingletonScope(); container.bind(MODEL.DatasetManager).to(DatasetManager).inSingletonScope(); container.bind(MODEL.Canvas).to(Canvas).inSingletonScope(); container.bind(MODEL.Component).to(Component); container.bind(FACTORY.Canvas).toFactory((ctx: interfaces.Context) => { return (config: CanvasConfig) => { const canvas = ctx.container.get(MODEL.Canvas); canvas.init(config); return canvas; }; }); container.bind(FACTORY.Component).toFactory((ctx: interfaces.Context) => { return (config: ComponentConfig) => { const component = ctx.container.get(MODEL.Component); component.init(config); return component; }; }); const getPluginByType = (type: string, ctx: interfaces.Context, model: symbol) => ctx.container.isBoundNamed(model, type) ? ctx.container.getNamed(model, type) : null; container .bind(FACTORY.ComponentPlugin) .toFactory((ctx: interfaces.Context) => (type: string) => getPluginByType(type, ctx, MODEL.ComponentPlugin)); container .bind(FACTORY.ConfigPanelPlugin) .toFactory((ctx: interfaces.Context) => (type: string) => getPluginByType(type, ctx, MODEL.ConfigPanelPlugin)); export default container;