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

Feature Request: unbindOne/rebindOne #1477

Open
dreamerblue opened this issue Aug 12, 2022 · 1 comment
Open

Feature Request: unbindOne/rebindOne #1477

dreamerblue opened this issue Aug 12, 2022 · 1 comment
Assignees

Comments

@dreamerblue
Copy link

Background

When using Inversify with possible multi-injection case, our framework have some requirements to control bound dependencies:

container.bind('Id').to(ClassA);
container.bind('Id').to(ClassB);
container.bind('Id').to(ClassC).inSingletonScope();

// In some cases like dynamic replacement or HMR clear, we need to unbind/rebind one dependency
// For example, to unbind `ClassB` only:

// cuz `container.get` can only return the instance, so we need to do use more complex way to maintain the constructor map in a wrapped method
const allBound = container.getAll('Id__ctor');
const index = allBound.indexOf(ClassB);
if (index > -1) allBound.splice(index, 1);
container.unbind('Id');
allBound.forEach(item => container.bind('Id').to(item));

Even we can self maintain the constructor map, it's not enough. We still need other metadata like scope, it will be a complex work.

Proposal

We are requesting a series methods to unbind/rebind a specified dependency like this:

container.unbindOne('Id', ClassB);
container.rebindOne('Id', ClassB).to(NewClassB);
@Jameskmonger
Copy link
Member

Hi @dreamerblue, apologies for the late response here, the project went through a period of low maintenance.

Do you think the solution proposed by @logikaljay for an unbindTagged method will suit your needs here? We are aiming to publish this functionality in the 6.1.0 release.

cc @PodaruDragos

cc reacting users: @DerKatsche @jhechtf

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

No branches or pull requests

2 participants