Closed dimitridaras closed 6 years ago
My error. It appears that I have to be more specific with my DI registrations for the validator than I had to be with Web Api. I have to register the specific validators such as
builder.RegisterType<MyTypeValidator>().As<IValidator<MyType>>();
whereas with Web Api I didn't have to be so specific. I am using the decorator pattern, and with Autofac I could register the decorator via
builder.RegisterType<MyTypeHandler>()
.Named<IHandler<MyType, IEnumerable<ReturnType>>>("handler");
containerBuilder.RegisterGenericDecorator(typeof(ValidationDecorator<,>),
typeof(MyTypeHandler<,>),
fromKey: "handler");
Description
I am using Nancy.Validation.FluentValidation (v2.0.0--clinteastwood), but I am unable to register IValidator classes in my DI container (I am using Autofac), apparently because they are in an external assembly.
According to the documentation, you used to have to call AppDomainAssemblyTypeScanner.LoadAssemblies to explicitly scan those assemblies, but this class no longer exists. How should validators now be registered?
I am using NancyFX v2.0.0-clinteastwood and .Net Core v2.1. See https://stackoverflow.com/q/52655150/42119
Steps to Reproduce
AbstractValidator<T>
Cannot resolve parameter 'FluentValidation.IValidator
System Configuration
.Net Core v2.1 OSX 10.13.6