you wouldn't pass the iwriter's dependency through the calculator, the
calculator doesn't know the type of the iwriter.
if you want to create writer at runtime, you could pass the kernel to
calculator and have the calculator pull the iwriter from the kernel
based on a parameter
var writer = kernel.Resolve<IWriter>(key of writer to select);
or you could create a factory object to create the calculator
public class CalculatorFactory
{
public ctor(IWriterRegistery registry) {...}
public Calculator Create(criteria for writer)
{
foreach(var writer in registry)
{
if(!writer.meets(critiera) continue;
return new Calculator(writer.implementation);
}
}
}
or you could resolve the writer and then resolve the calculator
var writer = container.Resolve<IWriter>(key to writer);
var calculator = container.Resolve<ICalculator >(writer);
you could register an IWriter which is just a composite of the actual
resolvers and place the logic there
class AllWriters : IWriter
{
ctor(IWriter first, IWriter second){...}
void dosomething()
{
if(should use first) first.dosomething();
else second.dosomething();
}
}
or you could implement your own subdependencyresolver to resolve the
type of writer needed.
Daniel Hölbling wrote:
> Hello,
>
> I am currently facing a interesting problem with my Windsor object creation.
>
> I have a service that calculates something and then calls a Writer service
> to save this calculation.
>
> So I have Calculator depend on IWriter through it's ctor.
>
> This all works.
> But now I have a special case where I need get a Calculator that is hooked
> up to a decorated IWriter that has one of it's dependencies supplied at
> runtime.
> In more concrete terms I try to apply a filter through the decorator, so I
> need to resolve a Calculator object that depends on a Filtered IWriter (with
> a runtime-supplied filter argument) and the Filter-Decorator then passes the
> call on to the "real" IWriter that then goes into the DB.
>
> Now, container.Resolve<Calculator>(arguments) would work if I need to pass