我得到 “System.StackOverflowException是未处理的” 公共堆栈溢出问题,Asp.net MVC
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;
}
其他服务构建物:
私人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;
}
“SessionService”的构造函数中发生了什么? – 2010-11-11 01:00:59
添加服务构建问题。 – scottrakes 2010-11-11 01:31:02
如果您将发布由'SessoinService'创建的所有对象的所有构造函数,我相信您会发现问题:) – 2010-11-11 01:36:37