Skip to content

[FEATURE] Separate Validation from Class Being Validated #23

@CodingFlow

Description

@CodingFlow

Is your feature request related to a problem? Please describe.
I'm trying to build a DDD microservice using Validly to validate domain objects in the domain layer. However, when referencing the domain object in the separate infrastructure project, it requires adding references to Validly packages, even though validation will only be done in the domain project. This seems to be because the validate method is generated as a method in a partial class.

The symptom shows up as CS0012 errors:

  • The type 'IValidatable' is defined in an assembly that is not referenced. You must add a reference to assembly 'Validly, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null'.
  • The type 'IInternalValidationInvoker' is defined in an assembly that is not referenced. You must add a reference to assembly 'Validly, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null'.

Describe the solution you'd like
An alternative format of the source generated code that does not use partial classes and is separate from the class to be validated that does not require adding references to Validly packages in every project that references the target class. Perhaps generating as an extension method would solve the issue? We'd also need some way to configure between the existing partial class way vs the new way as well.

Describe alternatives you've considered
I considered having the generated code be in a new validation class altogether, like Fluent Validations does it. We could go that way as well, but it would require users to instantiate the class before validating.

Additional context
Let me know if we need more info.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions