0
votes

My question is probably terrible, but here's what I'm trying to do using Castle Windsor in pseudo-code:

Register IFoo as Foo
Register IBar as Bar

When IFoo Is Passed Into a constructor And Being Resolved to Foo:
    Resolve IBar to Bar And pass typeof(Foo) to IBar.Create() method
        [ Resolve<IBar>().Create(typeof(Foo)) ]

The goal is that anytime I try to use IFoo as a dependency, I want to pass the implementation of IFoo (Foo)'s TYPE into a method on IBar - which will do some work to new up an instance of Foo and hydrate the Foo POCO.

Any ideas?

1

1 Answers

0
votes

Not entirely sure what you're trying to do from this example? The only thing I can suggest is this would be something handled in the concrete type (nothing to do with Castle Windsor). So:

Public Class Foo
{
    Public Foo(IBar bar)
    {
        bar.Create(typeof(Foo));
    }
}

Edit: What you seem to be saying is you want Foo to be constructed by Bar as a factory. In which case, coupling between a factory and the types it is responsible for creating is acceptable. You could therefore pass the factory IBar into any class that requires an instance of IFoo and call the create method directly. You can then, if you needed to, switch the factory implementation mappings of IBar to give you whatever concrete IFoo's required.