I have an object that I would like to access the Windsor Container. I have done this by registering the container with the container itself. Like so:
public class WindsorContainerInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
// no idea if this is a good idea or not
container.Register(Component.For<IWindsorContainer>().Instance(container));
}
}
public class Foo
{
public Foo(IWindsorContainer container)
{
_container = container;
}
private IWindsorContainer _container;
}
I haven't seen any examples with anyone doing it this way. I tend to see examples with people accessing the container by a static class or a singleton class.
So my question is. Are there any issues registering the container with the container itself?
Update
The scenario is perhaps not as simple as my initial code suggests. If my object had a particular dependency I would specify that in the constructor, like this public Foo(IBar bar)
.
In this scenario Foo doesn't entirely know what dependency it needs.
public class Foo
{
public Foo(IWindsorContainer container)
{
_container = container;
}
private IWindsorContainer _container;
public void Add<T>(T entity)
{
var bar = _container.Resolve<IBar<T>>();
bar.Create(entity);
}
}