owja / ioc

:unicorn: lightweight (<1kb) inversion of control javascript library for dependency injection written in typescript
MIT License
287 stars 13 forks source link

Feature: Plugins #54

Closed hbroer closed 2 years ago

hbroer commented 2 years ago

This new feature for @owja/ioc Version 2 implements plugins which will get executed just before the dependency is resolved.

The Plugin Interface

type Plugin<Dependency = any, Target = any> = (
    dependency: Dependency,
    target: Target | undefined,
    args: symbol[],
    token: MaybeToken<Dependency>,
    container: Container,
) => void;

It can directly added to a dependency after binding it

container.bind(symbol).to(class).withPlugin(plugin);

It can added to the container itself and get executed with all dependencies

container.addPlugin(plugin);

ToDo