I need to use Castle Windsor to automatically resolve some kind of services that are dependent on another parameter of the constructor where they are referenced. Here is a simple example:
the service I want to resolve is:
public interface IDependentParameter
{
IValue Value;
object Something;
}
Implemented by :
public class DependentParameter : IDependentParameter
{
public DependentParameter(IValue value)
{
Value = value;
}
public IValue Value;
public object Something;
}
IValue is another service that I can inject manually into the constructor
My dependant class looks like:
public class DependentClass : IDependentClass
{
IValue Value {get; protected set;}
IDependentParameter DependentParameter{get; protected set;}
public DependentClass (IValue value, IDependentParameter dependentParameter)
{
Value = value;
DependentParameter= dependentParameter;
}
}
The resolution code should be like:
var dependant = container.Resolve<IDependantClass>(new { value = knownValue });
On other posts, I saw solutions referencing AbstractFactory or TypedFactoryFacility. but the drawbacks I see on that solutions are:
- Unable to know just by looking at DependentClass constructor which services are needed (we will see just the factory service).
- How to implement the factory so that it can reference the castle windsor container to resolve IDependentParameter and not the new keyword. I absolutly need an instanciation using castle because I'm creating dynamic proxies instead.