Project structure and Validation/Validator

I’m going through the documentation and

Host Project
ServiceInterface Project
ServiceModel Project
Test Project

Since the goal is to have all the Dto’s in the ServiceModel Project and keep this dependency-free in which project should the Fluent Validators be kept?

For example, the documentation says:

Building functionality around POCOs - You can use the same POCO in ServiceStack as a DTO, OrmLite Data Model, Cache, Session, Config, etc

I’m planning on reusing the DTO’s used for the data model in my service. In which project would you typically put the Validators? If the goal is to keep the ServiceModel Project logic and dependency-free does it mean these should be on their own Project especially considering these validators could be used in other projects outside the service?

As per the documentation, the ServiceModel Project should only reference ServiceStack.Interfaces.dll.

So adding the validators in this project would pull in more dependencies but since these validators could be used by other projects outside the service I’m not sure what’s the best approach for this.


P.s. Sorry the dto approach is kind of new for us and we have a lot of existing classes with their own constructor performing some initialization logic in our legacy project and we are kind of working backward from a more monolithic code base to our goal of having things split in services etc. and working toward clean poco that are implementation and logic free is a bit of a mental shift…

The ServiceModel should remain dependency-free & only reference the impl/dep-free ServiceStack.Interfaces dependency. The ServiceInterface project is where your Services Implementation & logic should go & is typically where you’d define your FluentValidation Validators.

Although if you use declarative validators they’re defined on your DTOs which are still implementation-free.


I’m thinking of keeping these validators in a separate projects since it would make more send to reference that project instead of the service where they could potentially be used. How would we need to configure service stack to detect that specific project with the validator so the auto wiring works?


You can register all validators in an Assembly with Container.RegisterValidators(), e.g:

1 Like