inversify / InversifyJS

A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
http://inversify.io/
MIT License
11.33k stars 718 forks source link

Add "transaction" scope support #13

Closed remojansen closed 9 years ago

remojansen commented 9 years ago

When adding a binding allow "transaction" as scope.

Users can then create a "transaction" with:

kernel.beginTransaction("inteface");

And finish it with:

kernel.endTransaction("inteface");

Between beginTransaction and endTransaction if resolve is invoked:

kernel.resolve<inteface>("inteface");

The IoC container will use singleton scope.

If resolve is invoked before beginTransaction has been invoked the IoC container will use transient scope.

This is useful when we want a module to be a singleton within a scope. If we are in a scope (e.g.controller) and we navigate to a different scope (e.g. another controller) we might want our module to stop using singleton scope or create a new singleton within the new scope. All we need to do is to invoke beginTransaction when creating a scope (e.g. navigating to a controller) and endTransaction when leaving the scope (e.g. disposing the controller).

remojansen commented 9 years ago

I decided that this feature will not be implemented I will implement a much more powerful feature "contextual binding" https://github.com/inversify/InversifyJS/issues/15