我正在使用 NRules 来定义规则并尝试在 NRules 基类中使用接口,但是出现了问题,并且出现“没有为此对象定义无参数构造函数”错误。这是我的接口定义
{
public interface ICalcDiscount
{
public void ApplyPoint(int point);
}
public class CalcDiscount:ICalcDiscount
{
private readonly UniContext _context;
public CalcPoint(UniContext context)
{
_context = context;
}
public void ApplyDiscount(int d)
{
_context.Discount.Add(new Discount{ CustomerId = 1, d= d});
_context.SaveChanges();
}
}
}
NR规则类
public class PreferredCustomerDiscountRule : Rule
{
private readonly ICalcDiscount _d;
public PreferredCustomerDiscountRule(ICalcDiscount d)
{
_d = d;
}
public override void Define()
{
Book book = null;
When()
.Match(() => book);
Then()
.Do(ctx => _c.ApplyDiscount(10));
}
}
当 NRules 开始加载程序集 MissingMethodException:没有为此对象定义无参数构造函数时,我收到一个错误。
//Load rules
var repository = new RuleRepository();
repository.Load(x => x.From(typeof(PreferredCustomerDiscountRule).Assembly));//problem is here!
//Compile rules
var factory = repository.Compile();