how to resolve a dependency between two tightly coupled namespace(in different assembly)?

旧时模样 提交于 2019-12-11 20:18:52

问题


suppose i have an interface called ITestService with it's paired implementation, lets call it DefaultTestService in Assembly "A". I register DefaultTestService class as ITestService service in Autofac container. On the other hand assembly "A" has a reference to assembly "B".now I want to resolve DefaultTestService through it's corresponding interface (ITestService) in assembly "B", for doing this first I have to add reference to assembly "A" so that I can access and pass ITestService to Resolve<T>() method.

circular dependency !

ok.we can solve it by assigning a key for a component and resolve it by key.but what if the dependency not registered by me (and a key not assigned to it)?

Any idea? thanks for you'r suggestion.


回答1:


If assembly A depends on B and both assemblies need ITestService, this interface must be defined in assembly B, or a third assembly that both A and B depend on.



来源:https://stackoverflow.com/questions/13507505/how-to-resolve-a-dependency-between-two-tightly-coupled-namespacein-different-a

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