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:
|
public NamedPipeDistributedSubscriber(NamedPipeWorker worker, MessagePipeInterprocessNamedPipeOptions options, IAsyncSubscriber<IInterprocessKey, IInterprocessValue> subscriberCore, FilterAttachedMessageHandlerFactory syncHandlerFactory, FilterAttachedAsyncMessageHandlerFactory asyncHandlerFactory) |
--
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?
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:
I assume the following is causing the issue. Inside NamedPipeDistributedPublisherSubscribercs (lifetime: singleton) a NamePipeWoker (lifetime: scoped) is injected:
MessagePipe/src/MessagePipe.Interprocess/NamedPipeDistributedPublisherSubscribercs.cs
Line 37 in 94ec087
--
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?