Stack Overflow问题,Asp.net MVC

时间:2010-11-11 00:43:01

标签: asp.net-mvc model-view-controller stack-overflow

我在公共

上收到“System.StackOverflowException未处理”
VolunteerDBEntities() : base("name=VolunteerDBEntities", "VolunteerDBEntities")
        {
            OnContextCreated();
        }

当我改变这种情况时会发生这种情况:

   public class OrganizationService : IOrganizationService
    {

        private IValidationDictionary _validationDictionary;
        private IOrganizationRepository _repository;

        public OrganizationService(IValidationDictionary validationDictionary)
            : this(validationDictionary, new OrganizationRepository())
        { }


        public OrganizationService(IValidationDictionary validationDictionary, IOrganizationRepository repository)
        {
            _validationDictionary = validationDictionary;
            _repository = repository;
        }
...}

对此:

public class OrganizationService : IOrganizationService
    {

        private IValidationDictionary _validationDictionary;
        private IOrganizationRepository _repository;
        private ISessionService _session;

        public OrganizationService(IValidationDictionary validationDictionary)
            : this(validationDictionary, new OrganizationRepository(), new SessionService())
        { }


        public OrganizationService(IValidationDictionary validationDictionary, IOrganizationRepository repository, ISessionService session)
        {
            _validationDictionary = validationDictionary;
            _repository = repository;
            _session = session;
        }
...}

我对这一点毫无头绪。我为单元测试设置了这个,每当我向这个服务添加一个类变量时,它就会崩溃。我可以将一个类变量添加到另一个服务或创建一个服务,复制这个减去接口,它的工作原理。有什么想法吗?

会话服务构造:

   public class SessionService: ISessionService 
    {
        private IMembershipService _membershipService;
        private IVolunteerService _volunteerService;
        private IMessageService _messageService;

          public SessionService() 
            : this(new AccountMembershipService(null), new VolunteerService(null), new MessageService())
        {}


          public SessionService(IMembershipService membershipservice, IVolunteerService volunteerservice, IMessageService messageservice)
        {
            _membershipService = membershipservice;
            _volunteerService = volunteerservice;
            _messageService = messageservice;
        }

其他服务构造:

private IValidationDictionary _validationDictionary;    private IVolunteerRepository _repository;    private IOrganizationService _orgservice;

public VolunteerService(IValidationDictionary validationDictionary) 
    : this(validationDictionary, new VolunteerRepository(), new OrganizationService(null))
{}


public VolunteerService(IValidationDictionary validationDictionary, IVolunteerRepository repository, IOrganizationService orgservice)
{
    _validationDictionary = validationDictionary;
    _repository = repository;
    _orgservice = orgservice;

}



public class AccountMembershipService : IMembershipService
{
    private readonly System.Web.Security.MembershipProvider _provider;
    private IValidationDictionary _validationDictionary;
    private IVolunteerService _volservice;
    private IEmailService _emailservice;

    public AccountMembershipService(IValidationDictionary validationDictionary)
        : this(validationDictionary, null, new VolunteerService(null), new EmailService())
    {
    }

   public AccountMembershipService(IValidationDictionary validationDictionary, System.Web.Security.MembershipProvider provider, VolunteerService volservice, EmailService emailservice )
    {
        _validationDictionary = validationDictionary;
        _provider = provider ?? Membership.Provider;
       _volservice = volservice;
       _emailservice = emailservice;
    }

1 个答案:

答案 0 :(得分:1)