Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Akka.DependencyInjection: add a TestResolver to use during unit testing? #5167

Closed
Aaronontheweb opened this issue Aug 4, 2021 · 1 comment

Comments

@Aaronontheweb
Copy link
Member

Is your feature request related to a problem? Please describe.
Per the motivation for this API change originally: #4814

I propose a change to the ServiceProvider where instead of passing in an IServiceProvider we instead pass in a IDependencyResolver interface, by default this IDependencyResolver will be a SeriveProviderDependencyResolver that uses the IServiceProvider to resolve any DI dependencies. This will allow others to create their own implementations of the IDependencyResolver for testing.

I now find myself in the position of having this very use case as I write some integration tests for our upcoming Akka.Cluster.Sharding persistence repair tool and I need to be able to inject some lightweight dependencies into an actor that also needs to be created using DependencyResolver.Props.

I wonder - would it be worthwhile to include a built-in implementation of the IDependencyResolver for the explicit use case of testing only?

This class wouldn't really be part of the public API even though it would be a public class.

Describe the solution you'd like
A builder-style pattern for being able to quickly compose a lightweight IDependencyResolver that is fully decoupled from Microsoft.Extensions.DependencyInjection.

Describe alternatives you've considered
Just mocking up and using the IServiceProvider inside my unit tests anyway.

Additional context
I'm looking for feedback from other users who have similar use cases and might be interested.

@Aaronontheweb
Copy link
Member Author

The Akka.Hosting.TestKit, which uses a real IServiceCollection instead of a fake or a mock, ended up being the right solution to this problem: https://github.com/akkadotnet/Akka.Hosting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant