Unity Resolve中的堆栈溢出异常

时间:2018-08-24 21:41:08

标签: c# unity-container

当我要进行解析时,统一容器StackOverflowException的类型出现在:

   public class UserValidator : Validator<User>
   {
        readonly IBaseService<User> _service;
        public UserValidator()
        {
            _service = ApplicationResolver.Instance.Resolve<IBaseService<User>>();
            RuleFor(user => user.Email).EmailAddress();
        }

    }

BaseService

  public BaseService(IBaseRepository<T> repository, IValidator<T> validator)
  {
     Repository = repository;
     Validator = validator;
  }

Register

container.RegisterType<IValidator<User>, UserValidator>();

我应该改变图案吗?

1 个答案:

答案 0 :(得分:0)

我有BaseService取决于Validator,而Validator取决于BaseService

用于Repository从数据存储中存储/检索实体。