Skip to content

Instantly share code, notes, and snippets.

@tswistak
Created August 25, 2018 11:47
Show Gist options
  • Save tswistak/0a5ec4d0bb48fbc2e544e06b7f768607 to your computer and use it in GitHub Desktop.
Save tswistak/0a5ec4d0bb48fbc2e544e06b7f768607 to your computer and use it in GitHub Desktop.
InversifyJS with React, listing 2
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>;
}
}
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