'Autofac Circular Component Dependency Detected' Error

一曲冷凌霜 提交于 2019-11-28 12:38:43

If a UserService needs an IMailService and a MailService needs an IUserService you have a dependency loop. I see a couple of options:

  1. Does your UserService need an IMailService right away? Could you pass one in when it needs to send a message?

  2. Can either query the resolver on-demand - that is, don't pass IUserService to MailService in the constructor but rather code MailService to resolve IUserService when it needs it?

Autofac has documentation on how to handle circular dependencies that might help here. You can get it to work if you follow the guidance there (which boils down to: make one of the dependencies a property rather than a constructor dependency).

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