Repository: dotnet/orleans

Issue #8219: [Error Orleans 7]: Cannot resolve scoped service 'Orleans.Streams.StreamDirectory' from root provider.
Created: 2022-12-09T08:01:27Z
Hi
The exception is thrown when we create a singleton service and implement ILifecycleParticipant and then call GetStream from IStreamProvider:
async Task ILifecycleObserver.OnStart(CancellationToken cancellationToken)
{
    Logger.LogInitializing(_logger, _hubName, _serverId);
    _streamProvider = _clusterClient.GetStreamProvider(PusherStream.StreamProvider);
    _serverStream = _streamProvider.GetStream<ClientMessage>(_serverId, PusherStream.ServerStream);
}

The participant state is ServiceLifecycleStage.Active.
The error detail:
2022-12-09 11:02:21    [Error-11:02:21.050 +03:30] Exception during Silo.Start System.InvalidOperationException: Cannot resolve scoped service 'Orleans.Streams.StreamDirectory' from root provider.
2022-12-09 11:02:21    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.ValidateResolution(Type serviceType, IServiceScope scope, IServiceScope rootScope)
2022-12-09 11:02:21    at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
2022-12-09 11:02:21    at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
2022-12-09 11:02:21    at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
2022-12-09 11:02:21    at Orleans.Runtime.Providers.SiloStreamProviderRuntime.GetStreamDirectory() in /_/src/Orleans.Streaming/Providers/SiloStreamProviderRuntime.cs:line 127
2022-12-09 11:02:21    at Orleans.Providers.Streams.Common.PersistentStreamProvider.GetStream[T](StreamId streamId) in /_/src/Orleans.Streaming/PersistentStreams/PersistentStreamProvider.cs:line 158
2022-12-09 11:02:21    at Orleans.Streams.StreamProviderExtensions.GetStream[T](IStreamProvider streamProvider, String ns, String id) in /_/src/Orleans.Streaming/Providers/IStreamProvider.cs:line 73
2022-12-09 11:02:21    at DoctorCode.Oms.Pusher.Sockets.OrleansHubLifetimeManager`1.Orleans.ILifecycleObserver.OnStart(CancellationToken cancellationToken) in D:\Projects\oms\pusher\DoctorCode.Oms.Pusher\Sockets\OrleansHubLifetimeManager.cs:line 68

Duplicate issue #8215: SMS is not fully replaced in Orleans 7
Created: 2022-12-07T13:28:18Z
I am currently in the processes of trying to port a code base from Orleans 3.x to Orleans 7. The code is inspired heavily from the Orleans.SignalR implementation https://github.com/OrleansContrib/SignalR.Orleans/tree/master/src/SignalR.Orleans
Specifically this section of code: https://github.com/OrleansContrib/SignalR.Orleans/blob/5ae8310c7bad156638bab3a9441f3782140d953a/src/SignalR.Orleans/OrleansHubLifetimeManager.cs#L78-L79
For context and explanation, OrleansHubLifetimeManager is a singleton that contains all the connections to the server. By adding a Subscriber to a stream, we are able to execute code in the context of that singleton on every message and send messages to the individual connections, or all the connections.
The issue I am running into is that MemoryStreams seem to be the recommended replacement, as I need explicit subscriptions here. But when you attempt to call GetStream, it errors saying: Cannot resolve scoped service 'Orleans.Streams.StreamDirectory' from root provider.
Digging through the call stack, I can see that AddSiloStreaming does implemented this as a scoped service, and it also appears to be the same in 3.x but this wasn't an issue with the SMS Provider.
I am wondering if there is a recommended practice or some means without SMS to get a stream into this singleton or if this is a complete deal breaker in Orleans 7 that needs a re architecture on my end.

Closing comment (2022-12-28T17:32:25Z): Is it related to #8219?