我正在使用 Dapper Extensions 在配置为使用 Structuremap 的 MVC 应用程序中构建我的存储库。对于其中一个模型,我需要创建一个自定义映射来忽略一个字段。
public class ServiceMapper : ClassMapper<Service>
{
public ServiceMapper()
{
//Ignore this property entirely
Map(x => x.IsRunningNormally).Ignore();
//optional, map all other columns
AutoMap();
}
}
现在要调用这个映射器,我需要设置它,我在我的存储库的构造函数中调用这行代码。
DapperExtensions.DapperExtensions.DefaultMapper = typeof(ServiceMapper);
一旦我点击这一行,Structuremap 就会尝试解析类型并抛出异常:
ServiceMonitor.Infrastructure.ServiceMapper 不是 GenericTypeDefinition。MakeGenericType 只能在 Type.IsGenericTypeDefinition 为 true 的类型上调用。
我不确定这个错误是什么意思以及如何解决它?谁能指导我这里发生了什么?