问题
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