InversifyJS icon indicating copy to clipboard operation
InversifyJS copied to clipboard

Not able to access Container class private fields

Open tutok opened this issue 3 years ago • 0 comments

Many of the Container class fields should be protected instead of private. The current implementation of the Container class actually does not expose any way to "extend"/"improve"/"adjust to customer needs", because it is not possible to do anything more than is exposed via its public API.

https://github.com/inversify/InversifyJS/blob/f65cacf17d1482e6ef44493399c323f5471dea38/src/container/container.ts#L19

Expected Behavior

I would like to extend the Container class and have access to more advanced API, like _bindingDictionary

Current Behavior

Even I create a class MyContainer which is derived from class MyContainer I am not able to access its internal.

 class MyContainer extends Container {

   get bindings() {
       return this._bindingDictionary;  // not possible 
   }     
 }

Possible Solution

change access modifier of Container class fields from private to protected.

Not only for _bindingDictionary and not for each current private, but probably the vast majority of its private should be protected.

Steps to Reproduce (for bugs)

n/a

Context

I am not able to extend the functionality of Container class, the current implementation is almost identical to the one that would have sealed modifier.

Your Environment

  • Version used: n/a
  • Environment name and version (e.g. Chrome 39, node.js 5.4): n/a
  • Operating System and version (desktop or mobile): n/a
  • Link to your project: n/a

Stack trace

n/a

tutok avatar Dec 20 '21 07:12 tutok