c# - How do I gain access to a repository in a custom ValidationAttribute? -


public class uniquenameattribute : validationattribute {     private const string uniquenameviolationmessage = "this name taken. please select another.";      protected override validationresult isvalid(object value, validationcontext validationcontext)     {         //return somerepo.isuniquename(name)         //how access repo here?  tried di autofac came out null     } } 

i'm using dependency injection inject repositories web api. however, seems cannot inject validationattribute. comes out null if try inject. i'm using autofac di. there way can gain access repo?

note using web api, not mvc, cannot use mvc dependencyresolver.

builder.registertype<myrepository>().as<imyrepository>().instanceperrequest();  var container = builder.build(); globalconfiguration.configuration.dependencyresolver = new autofacwebapidependencyresolver((icontainer)container); ; 


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -