IOC on IValidationDictionary with Castle Windsor

后端 未结 2 1564
野性不改
野性不改 2021-01-21 18:02

I\'m new to Castle Windsor and am just using the latest version. I\'ve created entries for my repositories which are working fine but I have one final dependency that I\'m passi

2条回答
  •  粉色の甜心
    2021-01-21 18:29

    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()
       .WheveverEleseYouNeedHere()
       .OnCreate((k, controller) => 
          controller.ValidationService.Init(controller.ModelState)));
    

提交回复
热议问题