Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Scope Exception #93

@gergomiho

Description

@gergomiho

I am trying to inject a Scoped context to a Transient message handler and I am receiving an exception

Example code (removed the config part) :

services.AddRabbitMqClientTransient(new RabbitMqClientOptions{}).AddProductionExchange("events.user", new RabbitMqExchangeOptions{}).AddConsumptionExchange("events.essay", new RabbitMqExchangeOptions{}).AddAsyncNonCyclicMessageHandlerTransient<EssayCreatedMessageHandler>("essay.created", "events.essay");

The exception I receive is :

System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: RabbitMQ.Client.Core.DependencyInjection.Services.IMessageHandlerContainerBuilder Lifetime: Singleton ImplementationType: RabbitMQ.Client.Core.DependencyInjection.Services.MessageHandlerContainerBuilder': Cannot consume scoped service 'UserAPI.Infrastructure.UserContext' from singleton 'RabbitMQ.Client.Core.DependencyInjection.Services.IMessageHandlerContainerBuilder'.) (Error while validating the service descriptor 'ServiceType: RabbitMQ.Client.Core.DependencyInjection.Services.IMessageHandlingService Lifetime: Singleton ImplementationType: RabbitMQ.Client.Core.DependencyInjection.Services.MessageHandlingService': Cannot consume scoped service 'UserAPI.Infrastructure.UserContext' from singleton 'RabbitMQ.Client.Core.DependencyInjection.Services.IMessageHandlerContainerBuilder'.)'

I think this shouldn't happen because I am registering the handler as Transient, and Transient can consume Scoped. The message doesn't change if I use AddRabbitMqClient. I've fixed it by using the CreateScope function, but this is not how it should behave.

.NET 5
RabbitMQ.Client.Core.DependencyInjection Version 4.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions