두 개의 서로 다른 서비스에 명령 줄 args (예 : string [] args)를 전달하려고합니다. 나는 많은 것을 시도했다. 가장 가까운 코드는 다음과 같다.Castle Windsor : 명령 행 인수를 여러 서비스에 전달하는 방법은 무엇입니까?
namespace CastleTest
{
static class Program
{
static void Main(string [] args)
{
IWindsorContainer container = new WindsorContainer();
container.Install(FromAssembly.This());
IService srv = container.Resolve<IService>(new Hashtable {{"args", args}});
srv.Do();
}
}
public class Installer : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<IService>().ImplementedBy<Service>());
container.Register(Component.For<IRole>().ImplementedBy<RoleService>());
}
}
public interface IRole
{
string Role { get; }
}
public class RoleService : IRole
{
private string[] args;
public RoleService(string[] args)
{
this.args = args;
}
public string Role { get { return args[1]; } }
}
public interface IService
{
void Do();
}
public class Service : IService
{
private readonly string[] args;
private readonly IRole service;
public Service(string[] args, IRole service)
{
this.args = args;
this.service = service;
}
public void Do()
{
Console.WriteLine(args[0] + ": " + service.Role);
}
}
}
이 제공 실행 :이 만족하는 종속성이 같은
구성 요소 'CastleTest.RoleService'을 만들 수 없습니다. CastleTest.RoleService가 다음 종속성을 기다리고 있습니다. 키 (특정 키가있는 구성 요소) - 등록되지 않은 args입니다.
왜인가요? RoleService의 의존성 "args"가 만족스럽지 않은 이유는 무엇입니까? 그리고 더 중요한가? 내가 어떻게 해?
추신. FromAssembly를 사용하여 내 설치 관리자를 호출하므로 생성자 매개 변수를 전달하는 옵션이 없습니다 (afaik).