Dependency Injection with new Hosting Model #6066
-
I have a Blazor server app into which I am registering Akka.Net as follows:
Note how I am injecting the IServiceProvider into Actor props, and the actor's constructor creates a scope as follows:
However, in the Receive method of the Actor, the services that are resolved are NOT the same services that are resolved elsewhere in the application:
I'm trying to resolve a SignalR What am I missing? How do get my actor to use the same DI Service Provider as the rest of my Blazor Application? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
I may be wrong, as I am only new to Akka.net myself; however, I believe the issue may be to do with you attempting to pull a singleton via a scope. Instead of using the scope, try resolving the SignalRConnectionList directly from the Service Provider. The other thing I did for mine was to not inject the IServiceProvider and use IDependencyResolver (from Akka.DependencyInjection) instead. Here is an example using IHttpClientFactory: If you need to pull in a scoped dependency, you can create a scope from the Dependency Resolver like the following: |
Beta Was this translation helpful? Give feedback.
-
Thanks for your input @bauersystems. Because I was building the PoC based on the sharding-sqlserver sample I referred to earlier, I had the same Akka.Persistence.SqlServer.Hosting nuget reference in my Blazor project as that sample had in its web project. So I replaced that with the references that were being used in my from-scratch BlazorWithAkkaSignalRSln project, and suddenly the issue was resolved! Yay. But yay, the problem is solved! The actors in the Blazor project are now correctly doing SignalR! |
Beta Was this translation helpful? Give feedback.
Thanks for your input @bauersystems.
I took a couple of hours yesterday and did exactly that...built a new PoC adding in concepts one at a time.
The core issue turned out to be frickin' nuget references!!!!
Because I was building the PoC based on the sharding-sqlserver sample I referred to earlier, I had the same Akka.Persistence.SqlServer.Hosting nuget reference in my Blazor project as that sample had in its web project.
So I replaced that with the references that were being used in my from-scratch BlazorWithAkkaSignalRSln project, and suddenly the issue was resolved! Yay.
So it must be that Akka.Persistence.SqlServer.Hosting is referencing earlier versions of the core Akka.Hosting dll's…