redux-di-middleware
A redux middleware for dependency injection and async operations, written in Typescript
Install
npm install redux-di-middleware
Usage
Setting up with the Store
You can set up the middleware during the store creation.
;; // This service will be registered as a singleton in the default DI Container.// You can register services from another type as well into the same container.di.setInjectableinjectableService; ;
An example action
Injectable actions have to be a field called inject that must be a function (and can be async as well)
;
Using named containers
If you want to inject more than a simple instance you can use named containers.
;// sets to the default containerdi.setInjectableinjectableService; // sets to "myCustomContainer";di.setInjectableotherInjectableService, "myCustomContainer" // ... later in the Action// gets from the default container; // gets from "myCustomContainer";