Skip to content

Latest commit

 

History

History
20 lines (15 loc) · 601 Bytes

pre_destroy.md

File metadata and controls

20 lines (15 loc) · 601 Bytes

Pre Destroy Decorator

It is possible to add a @preDestroy decorator for a class method. This decorator will run before a service is unbinded for any cached instance. For this reason, only bindings in singleton scope can contain a method with this decorator.

@injectable()
class Destroyable {
    @preDestroy()
    public myPreDestroyMethod() {
        console.log('Destroyable is about to be unbinded!');
    }
}

const container = new Container();
container.bind<Destroyable>("Destroyable").to(Destroyable).inSingletonScope();

container.get("Destroyable");

container.unbindAll();