我有一个带有 Autofac 的 web api 应用程序。对于输入插入模型,我需要对指示相关实体的属性使用验证属性。
public class Comment
{
[Required]
[ExistentBookValidationAttribute]
public int BookId { get; set; }
}
在ExistentBookValidationAttribute
我需要访问业务服务来进行验证。由于 Autofac 不会将属性注入验证属性,因此我决定使用依赖解析器手动获取服务。但我不想使用GlobalConfiguration.Configuration.DependencyResolver
. 我想DependencyResolver
从 web api使用HttpConfiguration
。那有可能吗?HttpConfiguration.DependencyResolver
在验证属性中可以访问吗?