Dependency Injection and ModelStateWrapper

丶灬走出姿态 提交于 2019-12-05 18:22:21

Think.

Here's what you're trying to do:

  • In order to create product controller you need product service
  • in order to create product service you need product controller

you have a vicious circle, that's why you can't do it.

I dunno about implementation Unity, but conceptually, you need to break the circle, like this:

  • create product controller without passing product service to it
  • create product service and pass product controller's model state to it
  • inject product service into product controller via property injection

AFAIK unity does support property injection, but it requires you to put attribute onto the property. If I were you, I'd consider using a less invasive container (pretty much any other is better).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!