Try to use FluentValidation and I received an Exception

Hi I have issue with Fluent Validation and the IOC container
I want to use FluentValidator on my BackEnd Service and in my Xamarin.Forms Apps.

I start with the BackOffice solution:
When Any method it my ApplicationService (I use swagger to test) I have this exception

"responseStatus": {
    "errorCode": "Exception",
    "message": "Error trying to resolve Service 'LanBO.ServiceInterface.ApplicationService' or one of its autowired dependencies (see inner exception for details).",
    "stackTrace": "   at Funq.Container.ResolveImpl[TService](String name, Boolean throwIfMissing)\n   " +
	"at lambda_method(Closure , IResolver )\n   " +
	"at ServiceStack.Host.ContainerResolveCache.CreateInstance(IResolver resolver, Type type, Boolean tryResolve)\n   " +
	"at ServiceStack.Host.ServiceController.<>c__DisplayClass37_0.<RegisterServiceExecutor>b__0(IRequest req, Object dto)\n   " +
	"at ServiceStack.Host.ServiceController.<ExecuteAsync>d__47.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n   " +
	"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n   " +
	"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n   " +
	"at ServiceStack.Host.RestHandler.<ProcessRequestAsync>d__14.MoveNext()"

So I start by doing an Interface Class of my dto/table Data in a separate project

namespace LanBO.ServiceModel.Interface.Tables
{
    public interface IApplication: IConcurrency
    {
        string ApplicationCode { get;  set; }  
        string ApplicationDescription { get; set; }  
        bool Active { get; set; }
    }
}

Then my Validator in a separate project:

namespace LanBO.FluentValidator
{
    public class ApplicationValidator: AbstractValidator<IApplication>
    {
        public ApplicationValidator()
        {
            RuleFor(instance => instance.ApplicationCode)
                .NotNull()
                .NotEmpty();
            
            RuleFor(instance => instance.ApplicationDescription)
                .NotNull()
                .NotEmpty();
        }
    }
}

In my service where the Exception occur I do have

using System;
using FluentValidation;
using LanBO.FluentValidator;
using LanBO.ServiceModel;
using LanBO.ServiceModel.Tables;
using ServiceStack;
using ServiceStack.OrmLite;

namespace LanBO.ServiceInterface
{
    public class ApplicationService : Service
    {
        public IValidator<ApplicationValidator> ApplicationValidator; 
        public ApplicationService(IValidator<ApplicationValidator> appl) 
        {
           ApplicationValidator = appl;
        }
…

In my Apphost Configuration I have

appHost.Plugins.Add(new ValidationFeature
{
ScanAppHostAssemblies = false // Because I use a different Assembly to store my Validator
});
appHost.Container.RegisterValidators(typeof(ApplicationValidator).Assembly);

How can I debug this so I can see what assembly is missing ? I had in my project reference all the assemblies of my solution

Thanks!

Register an ExceptionHandler and debug the Exception thrown to inspect the InnerException.

1 Like
[2018-05-11 12:13:58.9908][Andres-MacBook-Pro][Fatal] UncaughtExceptionHandlers -> Request:ServiceStack.Host.NetCore.NetCoreRequest Exception:System.Exception: Error trying to resolve Service 'LanBO.ServiceInterface.ApplicationService' or one of its autowired dependencies (see inner exception for details). ---> System.Exception: Error trying to resolve Service 'FluentValidation.IValidator`1[[LanBO.FluentValidator.ApplicationValidator, LanBO.FluentValidator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' or one of its autowired dependencies (see inner exception for details). ---> System.InvalidOperationException: No service for type 'FluentValidation.IValidator`1[LanBO.FluentValidator.ApplicationValidator]' has been registered.

More details… but cannot understand how to solved it… still searching…
Thanks!