Is it possible to resolve Castle Windsor dependent properties if you don't have a container reference?

We have a solution with several projects representing the layers of our application. eg.

Domain

Data

Logics

Webui

Our Windsor Container Castle link to our web layer, and we then cascade these dependencies through our layers. For instance...

// 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 it works well until our managers have many members who have their own dependencies. When this happens, we ultimately eliminate both manager dependencies and their dependency dependencies and cascade them from the web level. This leads to some fairly large constructors.

Is there a more elegant way, for example, if the manager’s internal components allow its own dependencies without access to the container?

, - ( ), - WindsorContainer.Resolve() , , -, , .

+5
1

, , .Resolve<T>, , , . @Steven, Windsor, (/ ). , WindsorContainer , .

( MyThingyManager), . , ASP.NET MVC , . MVC3 DependencyResolver, .

, , Windsor , , (). , .

, :

public class Installer : IWindsorInstaller
{
        public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
        {
            container.Register(
                Component.For<IMyThingManager>().ImplementedBy<MyThingManager>(),
                Component.For<IFooRepository>().ImplementedBy<FooRepository>()
                );
        }
}

Global_asax.cs Application_Start - :

var container = new WindsorContainer();
container.Install(FromAssembly.This());
container.Install(FromAssembly.Containing(typeof(ComponentThatContains.MyThingManager.Installer)));

. , .

+6

All Articles