autofac - PropertiesAutowired 不适用于 Autofac 中的 RegisterGeneric
问题描述
我有一个没有泛型接口的泛型类,我尝试将其注册为
builder.RegisterGeneric(typeof(ValidationHelperBase<>)).PropertiesAutowired();
但是 PropertiesAutowired 在控制器中不起作用(会得到一个对象空引用异常),我只能像这样手动解决它
var instance = DependencyResolver.Current.GetService<ValidationHelperBase<Student>>();
我用谷歌搜索了这个问题,只找到了这样的东西Registering Generic Interfaces and classes with Autofac,问题是我的泛型类没有继承接口,只是一个普通的泛型类
public class ValidationHelperBase<T> where T : CustomTableBase
{
public virtual void CheckExist(int customTableItemId)
{
//do logic check, and throw exception when check failed
}
}
解决方案
推荐阅读
- python - TensorFlow 的 convert_image_dtype 破坏图像
- arrays - Mongodb/mongoose 模型 value/typeof 是 Object 而不是 Array
- nginx - 将子域重定向到 nginx Web 服务器时出现问题
- android - Firebase 没有将信息输入到我的 recyclerview android studio kotlin
- node.js - 拒绝加载图像'
' 因为它违反了以下内容安全策略指令:“img-src 'self' data:” - c - 位操作——为前 N 个设置位生成掩码
- php - 如何将php数组放入html表单?
- c# - 为什么我不能再用 cmd 编译 $
- java - Netty 将 HTTP/1.1 管道转换为双 HTTP/2 HTTP/1.1
- reactjs - 在 Monaco Editor 中使用热键?