Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to access Container class private fields #1410

Closed
tutok opened this issue Dec 20, 2021 · 2 comments
Closed

Not able to access Container class private fields #1410

tutok opened this issue Dec 20, 2021 · 2 comments

Comments

@tutok
Copy link

tutok commented Dec 20, 2021

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.

class Container implements interfaces.Container {

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

@c100k
Copy link

c100k commented Oct 4, 2024

Hey @tutok,
I know this issues is old, but have you found a workaround different from the one I present in #1584 ? Also, have you started working on proposing a PR for this ? If so, would be happy to help and collaborate.

@notaphplover
Copy link
Member

notaphplover commented Oct 21, 2024

Hey @tutok , @c100k , I'm giving some love to the project again.

I am afraid the container is not so simple. The binding dictionary is private for some very good reasons:

  • You should never update it manually without relying in the container public API.
  • The _bindingDictionary does not necesarily represent a real binding dictionary since ancestor containers might have _bindingDictionary properties which, all together can be used to build the real binding dictionary.

I don't think we should expose this dictionary for now. We might extend the container API with a getAllBindngs method instead to provide what you guys expect from _bindingDictionary.

The same could probably be discussed regarding other private fields. Talking about every private field of a container is way out of the scope of a single issue, I'll close this one for now. Feel free to discuss specific properties like _bindingDictionary in #1584

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants