-
Notifications
You must be signed in to change notification settings - Fork 46
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
Enhance bodi exceptions to include name of interface when duplicate registrations attempted #324
Conversation
…the Interface being registered when an instance for that interface has already been registered and resolved.
Added committer name to changelog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of small suggestions to consider; otherwise looks good.
Co-authored-by: Paul "Code Grump" Turner <[email protected]>
Co-authored-by: Paul "Code Grump" Turner <[email protected]>
@Code-Grump , thanks for the suggestions! |
Reqnroll/BoDi/ObjectContainer.cs
Outdated
@@ -364,7 +364,7 @@ public IStrategyRegistration RegisterTypeAs<TType, TInterface>(string name = nul | |||
public IStrategyRegistration RegisterTypeAs(Type implementationType, Type interfaceType, string name = null) | |||
{ | |||
if (!IsValidTypeMapping(implementationType, interfaceType)) | |||
throw new InvalidOperationException("type mapping is not valid"); | |||
throw new InvalidOperationException($"type mapping is not valid: {implementationType} -> {interfaceType}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message is quite technical. Consider rewording it to something like The provided type mapping is not valid. The {implementationType} is not assignable to {interfaceType}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx!
Once an interface has been registered and an instance of an object for that registration has been resolved, BoDi does not allow that registration to be altered. The exception message however is vague and does not indicate which Interface registration attempt caused the exception.
🤔 What's changed?
The error messages given to the BoDi exceptions have been enhanced to include type/interface information.
⚡️ What's your motivation?
Ease of diagnosing error situations when enhancing Reqnroll and Plugins.
🏷️ What kind of change is this?
📋 Checklist: