Skip to content

[Kernel][Container] Scope inconsistency #6985

@marcospassos

Description

@marcospassos

Hello,

I'm working on a multitenant application, using a multiple schema database approach. The context of my application is defined by the domain. So, I've a Doctrine listener that changes all entities schemas at runtime. The problem is I'm getting the following exception:

<service id="acme.subscriber.set_schema" class="Path/To/Class" public="false">
    <argument type="service" id="router.request_context"></argument>
    <call method="setContainer">
        <argument type="service" id="service_container" />
    </call>
    <tag name="doctrine.event_subscriber" />
</service>
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
{
     $request = $this->container->get('request');
}

Results in:

InactiveScopeException: You cannot create a service ("request") of an inactive scope ("request").

IMO, it seems like a contradiction. Once it is a http request, the request scope should not always be active? Furthermore, injecting the RouteContext, the returned host is localhost (the default value). I cant understand why the Context have not been initialized yet, once the request is one of the first things that is created:

$kernel = new AppKernel('dev', true);
//$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);

Is this a bug or an expected behavior?

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