【发布时间】:2023-03-09 04:20:01
【问题描述】:
我正在构建一个 mvc webapp,它与现有的 winforms 应用程序共享模型对象。我正在将 VAB 验证引入其中。我需要验证的项目之一是可以是 x 级别之一的 int。
我写了一个 LevelValidator,但它需要有可访问的关卡。
关于这段代码中的 new 调用,看起来我应该注入 LevelValidator 而不是 Levels? 其他方式?
public class LevelValidatorAttribute : ValueValidatorAttribute
{
protected override Microsoft.Practices.EnterpriseLibrary.Validation.Validator DoCreateValidator(Type targetType)
{
LevelValidator validator = new LevelValidator();
validator.Levels = this.Levels;
return validator;
}
[Dependency]
public Levels Levels { get; set; }
}
【问题讨论】:
标签: dependency-injection unity-container enterprise-library validation-application-bl