inversify-stereotype-decorators
v0.0.4
Published
a tiny wrapper around inversify and inversify-inject-decorators for @service @store @autowire etc. stereotypes
Downloads
1
Readme
Inversify Stereotype Decorators
experiment/wip
Usage
Install the package as well as it's peer dependencies
npm install --save inversify-stereotype-decorators inversify reflect-metadata
Create an IoC container and the stereotype decorators
// inversify.config.ts
import 'reflect-metadata';
import { Container } from 'inversify';
import { getStereotypes } from 'inversify-stereotype-decorators';
export const container = new Container();
export const { service, store, constant, autowire } = getStereotypes(container);
Use your new goodies!
import * as React from 'react';
import { service, store, autowire } from './inversify.config.ts';
@store
class TodoStore {
todos = ['hello'];
}
@service
class TodoService {
@autowire
private todoStore: TodoStore;
async createTodo(title: string) {
const todo = await someApiCall(title);
this.todoStore.todos.push(todo);
}
}
class TodoList extends React.Component {
@autowire
private todoStore: TodoStore;
render() {
return (
<div>
{this.todoStore.todos.map((todo) => <span>{todo}</span>)}
</div>
);
}
}