Register validator on attribute

I have to write a lot of validators, some of them are validating queries dto, and some are used for validation and other purposes. My project consists of modules encapsulated in a plug-in (a very cool solution! thx Service Stack Team!), the problem is that I sometimes forget to register the validator because the validator is created in one file and registered in another.

The problem can be solved as follows, but not all validators need to be registered so I don’t use this solution.

Plugins.Add(new ValidationFeature {
    ScanAppHostAssemblies = false

I use attributes to register validators, but I implement this logic every time.

public class AutoregisterValidator : Attribute { }

public class ValidatorAutoregistrationFeature : IPlugin {
        public void Register(IAppHost appHost) {
            if (appHost.GetPlugin<ValidationFeature>() != null) {
                var container = appHost.GetContainer();
                var assemblies = AppDomain.CurrentDomain.GetAssemblies();

                foreach (var assemblie in assemblies) {
                    foreach (var classType in assemblie.GetTypes()) {
                        var autoregistration = classType.GetCustomAttribute<AutoregisterValidator>();

                        if (autoregistration != null && !container.Exists(classType)) {

Please tell me how can I do this with the built-in ServiceStack features?

I don’t really understand the solution you’re looking for, it looks like you already have a custom solution that does what you want based on your personal use-case? If you want to re-use this logic, add it to a common library then register the same plugin.

What’s the issue with registering all validators in an assembly? If you only want adhoc validators registered you’re going to need a custom registration solution like this.