We have a solution whith multiple projects representing the layers of our application. e.g.
Domain
Data
Logic
WebUI
Our Castle Windsor container is referenced from our web layer and we then cascade these dependancies up through our layers. For example...
// In Domain
public interface IFooRepository
{
void DoSomething();
}
// In Data
public class FooRepository : IFooRepository
{
public void DoSomething()
{
// Something is done
}
}
// In Logic
public class MyThingManager
{
private readonly IFooRepository fooRepository;
public MyThingManager(IFooRepository fooRepository)
{
this.fooRepository = fooRepository;
}
public void AMethod()
{
this.fooRepository.DoSomething();
}
}
// In Web
// in some controller....
var newManager = new MyThingManager(WindsorContainer.Resolve<IFooRepository>());
newManager.DoSomething();
and this works nicely until our managers have lots of members that have their own dependancies. When this happens we end up resolveing both the managers dependancies and their dependancies depandancies and cascading them up from the web layer. This results is some rather large constructors.
Is there a more elegant way of, for example having the inner components of a manager resolve it's own dependancies without having access to the container?
Bear in mind that ONLY the web layer has access to the container (to prevent a circular project dependancy), so only the web layer can activly WindsorContainer.Resolve() the logic layer can't so the only way to cascade a dependancy without the containers assistance was to resolve it in the web layer then pass it up the chain using it's interface.