searchfe / inject-js Goto Github PK
View Code? Open in Web Editor NEWA tiny dependency Injection library for TypeScript.
Home Page: https://searchfe.github.io/inject-js/
A tiny dependency Injection library for TypeScript.
Home Page: https://searchfe.github.io/inject-js/
目前 Token 可以在使用时随意指定,可能会冲突,也可能不匹配 Provider 提供的具体 Service 类型。
此外,还应该提倡编写 provider 的地方,同时应该提供对应的 token。使用时一起引入,比如类似这样:
// 定义处
class QueryService {}
export QUERY_TOKEN = createToken<QueryService>()
export function queryFactory(): QueryService { return new QueryService(); }
// 使用处
import { QUERY_TOKEN, queryFactory } from './query.factory'
container.addFactory(QUERY_TOKEN, queryFactory)
依赖注入的用处在于,依赖接口而非具体的类。但目前 token 只能是 class,或者手动指定的 Symbol、string,问题是:
如果支持接口本身作为token就可以解决这些问题。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.