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

Check if Dependency Resolver is configured to avoid a NullReferenceException #3619

Conversation

augustoproiete
Copy link
Contributor

When using the DI() extension methods on ActorSystem or IActorContext without having properly configured an IDependencyResolver we currently get a NullReferenceException (e.g. 1, 2).

using (var system = ActorSystem.Create("mySystem"))
{
    var actorRef = system.DI().Props<MyActor>(); // Throws NullReferenceException
    // ...
}

This PR adds a check on the constructors of DIActorSystemAdapter and DIActorContextAdapter to verify if a dependency resolver exists, and throws an InvalidOperationException with a clear message of what the problem is.


using (var system = ActorSystem.Create("mySystem"))
{
    var actorRef = system.DI().Props<MyActor>(); // Throws InvalidOperationException
    // ...
}
Unhandled Exception: System.InvalidOperationException:
The Dependency Resolver has not been configured yet

@augustoproiete augustoproiete force-pushed the add-check-for-dependency-resolver branch 2 times, most recently from 40ae52b to 9d2a26c Compare October 16, 2018 23:05
@augustoproiete augustoproiete force-pushed the add-check-for-dependency-resolver branch from ac5ac2e to 80f663d Compare October 24, 2018 21:42
Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Much clearer than what we were doing before.

@Aaronontheweb Aaronontheweb added this to the 1.3.10 milestone Oct 25, 2018
@Aaronontheweb Aaronontheweb merged commit 912ddac into akkadotnet:dev Oct 26, 2018
@augustoproiete augustoproiete deleted the add-check-for-dependency-resolver branch October 27, 2018 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants