Skip to content

Can't use contextual binding without default bind #14541

@jaswdr

Description

@jaswdr

I have a situation where I have a interface that a class in each module need to implement, I don't have a default module, so, my idea is to only use the contextual binding, see code:

        $this->app->when('ModuleXController')
            ->needs('GlobalXContract')
            ->give('ConcretClassModuleX');

But I'm facing the Target GlobalXContract is not instantiable while building ModuleXController

This works when I do something like:

        $this->app->bind('GlobalXContract', 'ConcretClassDefault');
        $this->app->when('ModuleXController')
            ->needs('GlobalXContract')
            ->give('ConcretClassModuleX');

My question is, is it not more interesting to make optional the default binding when using contextual binding ?

Regards.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions