Skip to content

Feature Request: Ability To Unbind @named Target #447

@dac514

Description

@dac514

Hi,

I am using the @inject syntax to do IoC. It's working as expected.

For unit tests I needed the ability to override the binding so that I could hotswap my class with a mock. Someone in #143 suggested a clever way to this:

kernel.unbind("HttpConfig")
kernel.bind("HttpConfig").to(customHttpConfig)

However, my issue is that the object I want to override is declared using this syntax:

kernel.bind<ActiveDirectory>('Helper').to(ActiveDirectory).inSingletonScope().whenTargetNamed('ActiveDirectory');

Currently the only way I can override is:

    kernel.unbind('Helper');
    kernel.bind<ActiveDirectory>('Helper').to(MockActiveDirectory).inSingletonScope().whenTargetNamed('ActiveDirectory');

The problem with this approach is that I am only interested in overriding the 'ActiveDirectory' class and not all Helpers.

Help?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions