ardalis / modulith

Modulith is a dotnet new template for Modular Monoliths. It streamlines the creation of new .Net solutions and the addition of modules to existing ones.
MIT License
98 stars 9 forks source link

Use case Validation forces public classes #36

Closed MarkLFT closed 1 month ago

MarkLFT commented 1 month ago

I have purchased and watched both of your training courses on modular monoliths and found them to be really helpful. However, there is one issue that I have which I think causes a bad code smell. But I can't seem to find a way around it.

I have a module that receives message from a RabbitMQ queue, I then use Mediatr to pass the received message to a handler for processing. i.e., saving the record to a database.

These handlers have validators on the incoming messages to check them before the handler processes them.

In my web host, I am using the

''' builder.Services.AddValidatorsFromAssemblies(mediatRAssemblies); ```

command to register the mediatr validator assemblies. However, the assemblies are only registered if they are defined as public classes, not internal classes. This in turn forces the DTO object being passed to the handler to be public. But this DTO is only used within this module, and I do not want any other modules to be able to use it. So my preference is to keep it internal.

I have even tried to add the validators within the modules, so both the DTO and validator can be internal, but the validators are still not registered. Is there a way I can use internal classes as validators so all classes can be internal?

I have tried using this template and the sample code form the courses. but neither tackle this problem.

Thanks

MarkLFT commented 1 month ago

I found the solution to this. If anyone else comes across this issue, please check out https://github.com/FluentValidation/FluentValidation/issues/2202