InversifyJS icon indicating copy to clipboard operation
InversifyJS copied to clipboard

Investigate support for @preDestroy

Open remojansen opened this issue 8 years ago • 9 comments

Investigate @preDestroy see https://github.com/inversify/InversifyJS/issues/587#issuecomment-311881952 for more info...

remojansen avatar Jul 02 '17 21:07 remojansen

Remo, I find that very interesting.

Do you mean in general we need to provide some kind of a LifeCycleManager to handle the lifecycle calls or attach on* methods on the container similar to Windsor https://github.com/castleproject/Windsor/blob/aa9b8b353ee2e533d586495eec254e216f800c09/docs/lifecycle.md?

What do you think of the usage of interceptors? That potentially will give a different way of doing the onActivation handling https://github.com/castleproject/Windsor/blob/aa9b8b353ee2e533d586495eec254e216f800c09/docs/interceptors.md#interceptors.

Also, I was thinking of investigating of pairing them up with mixin style calls similar maybe to Django Rest Framework mixins http://www.django-rest-framework.org/tutorial/3-class-based-views/#using-mixins.

or this article

https://blog.mariusschulz.com/2017/05/26/typescript-2-2-mixin-classes

The idea is to attach mixins than are used independently for each lifecycle call.

What do you think?

theodesp avatar Jul 10 '17 16:07 theodesp

I'd like this very much. The typical case for me is working with Observables. If you subscribe to an observable within a service that is not a singleton, you should unsubscribe once the service is destroyed, otherwise you'll get notifications in a service that doesn't exist anymore.

just-jeb avatar Sep 17 '18 06:09 just-jeb

I'd would like this feature as well. We have a simmilar use case where we have a set of handlers for web socket messages. Currently we have to ensure the handlers live in singletone scope all the time or manage the lifecycle ourself as we do not know when to detach the handlers.

Having @preDestroy would make the code more SOLID as now we have to handle some concerns out of bean definition.

miroslavvojtus avatar Jan 09 '19 11:01 miroslavvojtus

@remojansen @parisholley has preDestroy been recently removed from any tags or npm releases? It seems to still exist on master but when I install 5.1.1 via NPM the preDestroy annotation is completely missing.

Screenshot 2021-06-05 at 18 25 47

faustbrian avatar Jun 05 '21 15:06 faustbrian

I also don't see onDeactivation handler for a Container instance and for a type binded in singleton scope.

@remojansen why isn't it in the NPM package?

Gradddev avatar Sep 07 '21 11:09 Gradddev

https://github.com/inversify/InversifyJS/issues/1319 - i don't think authors intend to push async changes until v6

parisholley avatar Sep 07 '21 12:09 parisholley

i also have an old build of my initial PR here that has all of the working async functionality, though their may be slight differences between it and master: https://www.npmjs.com/package/@parisholley/inversify-async

parisholley avatar Sep 07 '21 12:09 parisholley

#1319 - i don't think authors intend to push async changes until v6

@parisholley, the documentation in the master branch is misleading: https://github.com/inversify/InversifyJS/blob/master/wiki/pre_destroy.md and https://github.com/inversify/InversifyJS/blob/master/wiki/deactivation_handler.md

Gradddev avatar Sep 07 '21 13:09 Gradddev

#1319 - i don't think authors intend to push async changes until v6

you are right. I don't know what happened with the wiki. hopefully we finish work on v5 soon. Then I think we can release a v6. @dcavanagh

PodaruDragos avatar Sep 07 '21 13:09 PodaruDragos