0

I have a web api application with Autofac. For the input insert models I need to use validation attributes for the properties that indicate related entities.

public class Comment
    {
        [Required]
        [ExistentBookValidationAttribute]
        public int BookId { get; set; }
    }

In ExistentBookValidationAttribute I need to access a business service to do the validation. Since Autofac doesn't inject properties to the validation attributes I decided to use the dependency resolver to get the service manually. But I don't want to use GlobalConfiguration.Configuration.DependencyResolver. I'd like to use DependencyResolver from web api HttpConfiguration. So is that possible? Is HttpConfiguration.DependencyResolver accessable in the validation attributes?

Isadora
  • 423
  • 1
  • 5
  • 12
  • Show the validation attribute code in a [mcve] – Nkosi Nov 06 '17 at 13:56
  • 1
    I would recommend using https://github.com/JeremySkinner/FluentValidation instead of implementing the validation as an attribute – peco Nov 07 '17 at 10:06

0 Answers0