Skip to content

a tiny wrapper around inversify and inversify-inject-decorators for @service @store @autowire etc. stereotypes

Notifications You must be signed in to change notification settings

Place1/inversify-stereotype-decorators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>
    );
  }
}

About

a tiny wrapper around inversify and inversify-inject-decorators for @service @store @autowire etc. stereotypes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published