我在使用依賴注入的項目中存在循環依賴問題。環顧四周,除了重組(我也做了一些),似乎唯一避免它的方法是使用財產注入。我試過了,似乎沒有幫助,但我不知道爲什麼。這是導致問題的路徑。現在Ninject循環依賴 - 已經使用屬性注入
Activation path:
6) Injection of dependency IUserRepository into property UserRepository of type ModelFactory{UserRole}
5) Injection of dependency IUserRoleFactory into parameter userRoleFactory of constructor of type UserRoleService
4) Injection of dependency IUserRoleService into property UserRoleService of type InternalUserBehavior
3) Injection of dependency IInternalUserBehavior into parameter internalUserBehavior of constructor of type UserRepository
2) Injection of dependency IUserRepository into parameter userRepository of constructor of type HomeController
1) Request for HomeController
,它似乎知道它的使用屬性注入,所有的行爲和工廠都在同一範圍內(稱之爲範圍的權利,但我已經試過線程範圍太),還有UserRepository。
我對過程的理解是,它應該變爲4,並且能夠實際創建對象。此時,它應該有一個對HomeController,IUserRepository和IInternalUserBehavior的引用。然後它應該在5上工作,並將完成的IUserRoleService插入到InternalUserBehavior中。最後,它應該將以前實例化的用戶存儲庫(因爲它在相同的範圍內)插入到ModelFactory中的屬性中。所以我想我的問題的簡短版本是:爲什麼不是屬性注入解決我的循環依賴問題?
實際上,是的,班像她那樣。是的,我知道有一個循環依賴,但我迄今還沒有能夠解決它,這就是爲什麼我嘗試了財產注入。我正在看那個懶惰的綁定。 – Ixonal
看起來懶惰的初始化工作正確,因此將其標記爲答案。我可能會嘗試在稍後的時間點解決循環依賴問題,但現在,這會讓事情發生變化。謝謝您的幫助! – Ixonal