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

Enhance bodi exceptions to include name of interface when duplicate registrations attempted #324

Merged
merged 6 commits into from
Nov 19, 2024

Conversation

clrudolphi
Copy link
Contributor

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?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, etc. without changing behaviour)

📋 Checklist:

  • [X ] I've changed the behaviour of the code
    • [X ] I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • [ X] I have added an entry to the "[vNext]" section of the CHANGELOG, linking to this pull request & included my GitHub handle to the release contributors list.

…the Interface being registered when an instance for that interface has already been registered and resolved.
Added committer name to changelog
Copy link
Contributor

@Code-Grump Code-Grump left a 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.

Reqnroll/BoDi/ObjectContainer.cs Outdated Show resolved Hide resolved
Tests/Reqnroll.RuntimeTests/BoDi/RegisterTypeTests.cs Outdated Show resolved Hide resolved
clrudolphi and others added 2 commits November 11, 2024 10:31
@clrudolphi
Copy link
Contributor Author

A couple of small suggestions to consider; otherwise looks good.

@Code-Grump , thanks for the suggestions!

@@ -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}");
Copy link
Contributor

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}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Modified.

Copy link
Contributor

@gasparnagy gasparnagy left a comment

Choose a reason for hiding this comment

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

thx!

@gasparnagy gasparnagy merged commit 030e854 into main Nov 19, 2024
1 check passed
@gasparnagy gasparnagy deleted the Enhance_BODI_Exceptions branch November 19, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants