KO
|
EN
gitlite — search
Search
#typescript
#ai-agents
#ai
#dsh-plugin
#deepseek-harness
#open-source
#claude-code
#codex
#cli
#developer-tools
#react
#windows
power-di
★ 182
Open GitHub ↗
A lightweight Dependency Injection library.
Download README (.md)
Explore Similar Repositories
router-store
:
Bindings to connect the Angular Router to @ngrx/store
aframe-teleport-controls
:
A-Frame teleport controls component
amazon-sqs-java-messaging-lib
:
This Amazon SQS Java Messaging Library holds the Java Message Service compatible classes, that are used for communicating with Amazon Simple Queue Service.
wordpress
:
WordPress Plugin for Auth0 Authentication
WechatOriginalFile
:
check wechat sns photos without sending lucky money
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
power-di
?
Download (.md)
# Power DI [](https://travis-ci.org/zhang740/power-di) [](https://coveralls.io/github/zhang740/power-di) [](https://www.npmjs.com/package/power-di) [](https://github.com/zhang740/power-di/blob/master/LICENSE) A lightweight Dependency Injection library. Using es6 and other features, remove unnecessary concepts, easy and convenient to use. ## Install ```shell npm i power-di --save ``` ## Example ### a simple example ```ts import { IocContext } from 'power-di'; class AService { } // default instance, you can also new IocContext to get a instance. const context = IocContext.DefaultInstance; context.register(AService); const aService = context.get(AService); // a instance of AService ``` ### inject with key ```ts class AService { } const context = IocContext.DefaultInstance; context.register(AService, 'XService'); // key need a string or class, e.g super class or whatever class. context.get('XService'); ``` ### use with decorators ```ts const context = new IocContext(); @injectable() class NRService { } @injectable() class LITestService { @inject() public testService: NRService; } const test = context.get(LITestService); ``` ### collect impl or extends of some interface/base class ```ts class A { } @classInfo() class B extends A { } @classInfo() class C extends A { } @injectable() class LITestService { @imports({ type: A }) public testService: A[]; } const test = context.get(LITestService); // test.testService as A[]; ``` ### use in react ```tsx const context = new IocContext; class NRService { } context.register(NRService); class TestComponent extends Component<{}, {}> { @inject() service: NRService; componentDidMount() { t.true(this.service instanceof NRService); } render(): any { return null; } } create( <IocProvider context={context}> <TestComponent /> </IocProvider> ); ``` ## Class Loader Power DI introduced the concept of class loader. We can customize the find rule of ioc. #### [See the test case for details.](https://github.com/zhang740/power-di/tree/master/test)