Nie przekazanie ogólnych argumentów z Castle Windsor
Wydaje się, że istnieje problem z przekazywaniem ogólnych argumentówpodczas próby utworzenia sparametryzowanej instancji za pomocą Castle Windsor
Demo nieudanych prób przesłania ogólnych argumentów private static void Main(string[] args)
{
PassGenericParamAtResolutionTime();
Console.ReadLine();
}
private static void PassGenericParamAtResolutionTime()
{
Console.WriteLine("Passing generic argument fails");
var container = new WindsorContainer();
container.Register(Component.For<ISandCoordinator<Simpleton>>()
.ImplementedBy<SandCoordinator<Simpleton>>());
var runtimeConstructorParam = new GenericManager<Simpleton>(
"This Id Does Not Get Through");
var runtimeArguments = new Arguments(
new object[] {runtimeConstructorParam});
var shouldBeParameterizedCoordinator = container
.Resolve<ISandCoordinator<Simpleton>>(runtimeArguments);
Console.WriteLine(shouldBeParameterizedCoordinator.Log);
}
Wyjście konsoliPassing generic argument fails
Birth from parameterless constructor, which should not happen
A jeśli skomentuję poniżej bezparametrowy konstruktor, otrzymam następujący wyjątek:
Castle.MicroKernel.Resolvers.DependencyResolverException was unhandled
Missing dependency.
Component Sand.SandCoordinator`1[[Sand.Simpleton, WindsorSand, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] has a dependency on Sand.IGenericManager`1[Sand.Simpleton], which could not be resolved.
Make sure the dependency is correctly registered in the container as a service, or provided as inline argument.
Klasa demonstracyjna z dwoma konstruktoramiclass SandCoordinator<TSimpleton> : ISandCoordinator<TSimpleton>
where TSimpleton : ISimpleton
{
public SandCoordinator()
{
Log = "Birth from parameterless constructor, which should not happen";
}
public SandCoordinator(IGenericManager<TSimpleton> manager)
{
Log = "Birth from parameterized constructor";
Log += Environment.NewLine + "Born With Manager: " + manager.Id;
}
public string Log { get; private set; }
}
Rozwiązania / obejścia?Wiem, że jeśli utworzę nietypowy typinterface ISimpleSandCoordinator : ISandCoordinator<Simpleton>
i zarejestruj nie-generyczny interfejs, a następnie działa parametryzowana rozdzielczość, ale nie chcę przestać używać typów ogólnychCzy należy to zgłosić jako błąd w Castle Windsor?[ Korzystanie z Castle.Core.dll i Castle.Windsor.dll 3.1.0 (2012-08-05) ]