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

AssemblyScanner finds private classes #7027

Open
pardahlman opened this issue May 14, 2024 · 1 comment
Open

AssemblyScanner finds private classes #7027

pardahlman opened this issue May 14, 2024 · 1 comment

Comments

@pardahlman
Copy link

Describe the suggested improvement

Is your improvement related to a problem? Please describe.

We have an integration test suite where NServiceBus endpoints are started and message handlers with different behaviors are used to verify certain aspects of our code. The message handlers and related messages are declared as nested private classes to the test class.

Despite of this, the assembly scanner finds these private handlers and adds them to the DI container. This, in turn, makes the DI validation fail when building the IServiceCollection as the handlers from the other tests have constructor arguments not registered. Moreover, I can not exclude these handlers from the assembly scanning as they are private and not available to me (unless I get the assembly, find the type... but that does not feel right to me).

Describe the suggested solution

I can see how it would be a breaking change to only scan exported types. But to ignore private classes that implement IHandleMessages<> could perhaps be acceptable? Or if not, what about IHandleMessages<TMessage> where TMessage is private?

Describe alternatives you've considered

The workaround I have in place is to ignore the DI validation in my integration tests. That way, the handler is found, the container is invalid but the problematic services are never resolved.

Additional Context

No response

@NChaganlal
Copy link

Hi @pardahlman,
Thank you for raising this issue.
We will look into it and consider it for an upcoming enhancement release.

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

2 participants