MessagePipe.Interprocess - Scope issue on running in none production environment | with scope validation (ValidateScopes)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2k
- Forks
- 133
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I'm evaluating the MessagePipe.Interprocess using the NamedPipe.
I'm using the IDistributedSubscriber within a scoped Service and get the following exception if running inside none production environment (DOTNET_ENVIRONMENT != "Production") like development or staging.
Running the same code in a production enviornment works, but running it in an devleopment environment it fails.
This is because scope validation (ValidateScopes) not active and not running in production enviornments.
Exception details:
System.AggregateException
HResult=0x80131500
Message=Some services are not able to be constructed
Source=Microsoft.Extensions.DependencyInjection
StackTrace:
at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection`1 serviceDescriptors, ServiceProviderOptions options)
at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()
at Demo.IpcTests.dotNetFxConsoleApp.Program.<Main>d__0.MoveNext()
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
InvalidOperationException:
Error while validating the service descriptor 'ServiceType: Demo.IpcTests.Services.IServerService Lifetime: Scoped ImplementationType: Demo.IpcTests.Services.ServerService':
Cannot consume scoped service 'MessagePipe.Interprocess.Workers.NamedPipeWorker' from singleton 'MessagePipe.IDistributedSubscriber`2[System.String,Demo.IpcTests.Data.SampleData]'.
Inner Exception 2:
InvalidOperationException: Cannot consume scoped service 'MessagePipe.Interprocess.Workers.NamedPipeWorker' from singleton 'MessagePipe.IDistributedSubscriber`2[System.String,Demo.IpcTests.Data.SampleData]'.
I assume the following is causing the issue. Inside NamedPipeDistributedPublisherSubscribercs (lifetime: singleton) a NamePipeWoker (lifetime: scoped) is injected:
--
Changing the InstanceLifetime from Scoped to Singleton for NamedPipeInterprocess is workaround, maybe:
.AddNamedPipeInterprocess(Demo.IpcTests.Services.Constants.PipeNames.DotNetPipe, namedPipeOptions => {namedPipeOptions.InstanceLifetime = InstanceLifetime.Singleton;
})
--
Does someone know how to solve this issue? Or I'm doing some wrong?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/MessagePipe.Interprocess/NamedPipeDistributedPublisherSubscribercs.cs at the linked line, then reproduce the NamedPipe setup with ValidateScopes enabled in a non-production environment. Compare the scoped registration with the reported singleton workaround; done means the service provider builds without the scoped-worker/singleton-subscriber validation exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100