views:

50

answers:

2

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.HandlerException: Can't create component 'UserRepository' as it has dependencies to be satisfied. UserRepository is waiting for the following dependencies

How do I fix this?

+5  A: 

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

Krzysztof Koźmic
+1  A: 

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.

Igor Brejc