public intefrace ICommand {
void Execute();
}
public class A : ICommand {}
public class B : ICommand {}
public class MultiCommand : ICommand {
public MultiCommand(ICommand[] commands) {}
}
public DecoratorOne : ICommand {
public DecoratorOne(Icommand toDecorate) {}
}
public DecoratorTwo : ICommand {
public DecoratorOne(Icommand toDecorate) {}
}
ForREquesedType<ICommand>()
.TheDefaultIsConcreteType<A>
.EnrichWith(x => new DecoratorOne(x)
.EnrichWith(y => new DecoratorTwo(y)
.CacheBy(InstanceScope.Singleton);
InstanceOf<ICommand>()
.TheDefault.Is.OfConcreteType<B>
.EnrichWith(x => new DecoratorOne(x)
.WithName("secondCommand")
ForRequestedType<MultiCommand>()
.TheDefault.Is.OfConcreteType<MultiCommand>()
.TheArrayOf<ICommand>()
.Contains(y =>
{
y.TheDefault();
y.TheInstanceNamed("secondCommand")
})
.WithName("multi");
**
/// what I want to do
**
What I want is that A is the default. So wherever an ICommand instance is required, it will receive A. MultiCommand will have both A and B and will execute them in a loop.
**
//a problem with
**
B seems to be decorated several times. When I call , I get something in accordance with the new **. I guess it is decorated because of the definition that I have by default. A. How can I avoid this? ObjectFactory.GetNamedInsance<ICommand>("secondCommand")**new DecoratorOne(new DecorateOne(B)).
Also is there a proper way to insert an array into multicommand?
Thanks again, I'm new to the map structure, so any help would be appreciated.
UPDATE
TypeInterceptor, . , , "" . ,
RegisterInterceptor(new CommandDecoratorInterceptor());
ForRequestedType<ICOmmand>()
.TheDefaultIsConcreteType<A>()
.CacheBy(StructureMap.Attributes.InstanceScope.Singleton);
InstanceOf<ICommand>()
.Is.OfConcreteType<B>()
.WithName("secondCommand");
ForRequestedType<MultiCommand>()
.TheDefault.Is.OfConcreteType<MultiCommand>()
.TheArrayOf<ICommand>()
.Contains(y =>
{
y.TheDefault();
y.TheInstanceNamed("secondCommand");
});
Type , . MultiMonitor ().
;)