How do I set up Array/List dependencies in code with Castle Windsor?
I have the following classes:
class Repository : IRepository
class ReadOnlyRepository : Repository
abstract class Command
abstract CommandImpl : Command
{
public CommandImpl(Repository repository){}
}
class Service
{
public Service (Command[] commands){}
}
I register them in code as follows:
var container = new Container("开发者_JAVA百科WindsorCOntainer.config");
var container = new WindsorContainer(new XmlInterpreter("WindsorConfig.xml"));
container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel));
container.AddComponent("repository", typeof(RentServiceRepository));
container.Resolve<RentServiceRepository>();
container.AddComponent("command", typeof(COmmandImpl));
container.AddComponent("rentService", typeof (RentService));
container.Resolve<RentService>(); // Fails here
I get the message that "RentService is waiting for dependency commands"
What am I doing wrong?
Thanks,
You're not registering CommandImpl
as Command
, you're registering it as CommandImpl
.
if you do:
container.Register(Component.For<Command>().ImplementedBy<CommandImpl>());
it'll work.
I suggest you familiarize yourself with the documentation, especially installers and registration API
精彩评论