Created
August 25, 2018 11:47
-
-
Save tswistak/0a5ec4d0bb48fbc2e544e06b7f768607 to your computer and use it in GitHub Desktop.
InversifyJS with React, listing 2
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 * as React from "react"; | |
| import { lazyInject } from "./ioc"; | |
| import { IProvider } from "./providers"; | |
| export class Hello extends React.Component { | |
| @lazyInject("nameProvider") private readonly nameProvider: IProvider<string>; | |
| render() { | |
| return <h1>Hello {this.nameProvider.provide()}!</h1>; | |
| } | |
| } |
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 { Container } from "inversify"; | |
| import getDecorators from "inversify-inject-decorators"; | |
| import { IProvider, NameProvider } from "./providers"; | |
| const container = new Container(); | |
| container.bind<IProvider<string>>("nameProvider").to(NameProvider); | |
| const { lazyInject } = getDecorators(container); | |
| export { lazyInject }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment