Skip to content

Expose container binding dictionary #1584

@c100k

Description

@c100k

For multiple reasons, it can be useful to access a container's bindings : write some tests, check that the bindings are correct, export the bindings to a human readable format, etc.

Possibly related topic : #1410.

Expected Behavior

The Container has a _bindingDictionary field (https://github.com/inversify/InversifyJS/blob/master/src/container/container.ts#L25). Since the field is private, we could add a public getter for it.

Current Behavior

Right now, there is no getter so the only workaround is to access the field telling TypeScript to stop complaining with @ts-ignore.

console.log(container._bindingDictionary);

Even if it "works", it's hacky and not very ideal. Because of @ts-ignore, if for any reason inversify is updated and this field is renamed/removed, tsc won't complain and it will cause an error at runtime.

Possible Solution

Adding a getter to access the bindings map.

Steps to Reproduce (for bugs)

N/A

Context

N/A

Your Environment

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

Stack trace

Metadata

Metadata

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions