I've been successfully using the TestCluster to get grain instances for testing. The cluster was configured with several services in its service collection. The service interfaces are injected into the grain classes. There is a ServiceProvider
property on the test cluster instance and it has a GetService
method so I thought that I could obtain these services this way from test case code. When I try, I get null for whatever service I ask for. No problem getting grain instances so I know at least that part of it working. I'm sure the services are present because the related tests that rely on the services are passing.
Is it even possible to retrieve the services this way? It doesn't seem like the ServiceProvider
would even be there if there wasn't some intention that it can be used this way.
See also
Repost of question on Orleans repo Q&A
Can the TestCluster be used to obtain items from the service collection?
If you're setting up the
ClusterFixture
on your own, you can make your your services easily available by implementing theISiloConfigurator
interface. From the official docs here: https://learn.microsoft.com/en-us/dotnet/orleans/implementation/testing