J'ai un petit problème lors de la configuration d'un module Autofac. Je veux résoudre un service IValidator (Fluent Validator) avec un modèle de commande, mais je ne sais pas comment.Comment résoudre l'interface générique à partir du type de classe
Voici mes ordres:
public interface ICommand
public interface ICreateCommand<TDto> : where TDto is IDto
public CreateUserCommand : ICreateCommand<UserDto>
Voici mon validateur:
public CreateCommandValidator<TDto> : AbstractValidator<ICreateCommand<TDto>>
Je veux CreateCommandValidator
lors de la résolution IValidator<CreateUserCommand>
mais je reçois seulement ComponentNotRegisteredException
.
Ma config autofac:
var assembly = typeof(CommandModule)
.GetTypeInfo()
.Assembly;
builder.RegisterAssemblyTypes(assembly)
.AsClosedTypesOf(typeof(ICommandHandler<>))
.InstancePerLifetimeScope();
builder.RegisterType<CommandDispatcher>()
.As<ICommandDispatcher>()
.InstancePerLifetimeScope();
libraryAssembly = typeof(ICommand)
.GetTypeInfo()
.Assembly;
builder.RegisterAssemblyTypes(libraryAssembly)
.Where(x => x.IsAssignableTo<ICommand>())
.AsImplementedInterfaces();
builder.RegisterAssemblyTypes(libraryAssembly)
.AsClosedTypesOf(typeof(IValidator<>))
.InstancePerLifetimeScope();