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
> an argument to the calculator.
> But how do I supply the arguments to the subsequent IWriter lookup?
>
> Is there some way to pass arguments to subsequent resolves?
>
> The obvious fallback would be to simply construct that object by hand. But
> that's not really ideal imo.
>
> Any help would be greatly appreciated.
> greetings Daniel Hoelbling
>
> (PS: Sorry if this went to the list twice, I may have forgotten to change my
> from field to the one registered at google)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---