IOC on IValidationDictionary with Castle Windsor

狂风中的少年 提交于 2019-12-02 00:08:28
Mark Seemann

It seems like you have a circular dependency (never a good thing). You can get around it by using an Abstract Factory as described in this very similar question.

However, although you may be able to solve the problem like this, it would be better to redesign the API to make the circular dependency go away. Circular dependencies often indicate a design flaw.

You're doing it wrong, and your wrongdoing has nothing to do with the container you're using.

Just do it like this, if you absolutely need to:

public AccountController(IValidationService service)
{
    _validationService = service;
    _memSvc = new MembershipService(_validationService); 
}

then as you're registering your component, use an OnCreate method:

container.Register(
   Component.For<AccountController>()
   .WheveverEleseYouNeedHere()
   .OnCreate((k, controller) => 
      controller.ValidationService.Init(controller.ModelState)));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!