开发者

Windsor dependency

I have a class with constructor like this:

public UserRepository(IBlockRepository blockRepos)
{
}

and again, I have another class with the constructor like this:

public BlockRepository(IUserRepository userRepo)
{
}

this causes the Windsor error:

Castle.MicroKernel.Handlers.HandlerExceptio开发者_Python百科n: Can't create component 'UserRepository' as it has dependencies to be satisfied. UserRepository is waiting for the following dependencies

How do I fix this?


You have a cyclic dependency here. Chicken and egg problem so to speak. It's a design problem that has nothing to do with Windsor. Break the cycle in your code and Windsor will be able to build your objects just fine


In addition to what Krzysztof said: if you have to classes which depend on each other, this is a good indicator that the functionality shouldn't be split into these two classes the way it is now. You should try to merge them together and then split out the real one-way dependencies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜