Created
July 10, 2019 11:54
-
-
Save radzserg/6023eb8a74b80a064400ee11ed988339 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import DIContainer, { object, get, value, factory, IDIContainer } from "rsdi"; | |
| const config = { | |
| "ENV": value("PRODUCTION"), // define raw value | |
| "Storage": object(CookieStorage), // will instantiate an object of class CookieStorage without arguments | |
| "AuthStorage": object(AuthStorage).construct( | |
| get("Storage") // refer to dependency described above | |
| ), | |
| "BrowserHistory": factory(configureHistory), // factory callback | |
| }; | |
| const container = new DIContainer(); | |
| container.addDefinitions(config); | |
| const env = container.get<string>("ENV"); // PRODUCTION | |
| const authStorage = container.get<AuthStorage>("AuthStorage"); // object of AuthStorage | |
| const history = container.get<History>("BrowserHistory"); // object of History | |
| function configureHistory(container: IDIContainer): History { | |
| const history = createBrowserHistory(); | |
| const env = container.get("ENV"); // we have container and can get what we need. | |
| if (env === "production") { | |
| // do what you need | |
| } | |
| return history; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment