且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

节点情况下的Typescript IOC

更新时间:2022-06-24 22:36:09

在这种情况下如何整合IOC解决方案

How would I integrate IOC solution in such case

这是我推荐的一个非常受欢迎的库: https://github.com/inversify/InversifyJS

Here is a very popular library that I recommend : https://github.com/inversify/InversifyJS

使用外部模块根本不会更改代码.代替

Using external modules doesn't change the code at all. Instead of

kernel.bind(new TypeBinding<FooBarInterface>("FooBarInterface", FooBar));

生产

您只有

import {ProdFooBar} from "./prodFooBar";
kernel.bind(new TypeBinding<FooBarInterface>("FooBarInterface", ProdFooBar));

测试

import {MockFooBar} from "./mockFooBar";
kernel.bind(new TypeBinding<FooBarInterface>("FooBarInterface", MockFooBar));