Seemingly circular dependencies causing issues with Castle Windsor

后端 未结 3 1353
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 12:52

I have a IUserService (and other services) that I am registering in bulk in my ServiceInstaller.cs:

  container.Register(
                AllTypes.FromAssemb         


        
3条回答
  •  无人及你
    2020-12-21 13:32

    You need to either:

    1. Get rid of your circular dependencies (this is the preferred option), or
    2. Work around them, by using property injection, rather than constructor injection.

    Using property injection (as illustrated in Steven's answer) allows you to create instances of your classes without providing all the dependencies at the time of creation. The downside is that it is not as obvious to users of the class what they need to do to instantiate and fully configure the instance.

    For a nice explanation of how to refactor to remove a ciruclar dependency see this blog post by Miško Hevery:

    • Circular Dependency in constructors and Dependency Injection

提交回复
热议问题