我正在尝试解析继承模板类的对象
using System;
using Controller;
namespace Controller
{
public interface IControllerBase<T> where T:IViewBase
{
}
public class ControllerBase
{
public string ModuleName
{
get;
set;
}
}
public class ControllerBase<T> : ControllerBase, IControllerBase<T>
where T : IViewBase
{
public virtual T View {
get;
set;
}
public ControllerBase (T instance)
{
View = instance;
}
}
}
IControllerBase was added recently, just to match this strategy:
container.Register (Component.For(typeof(IControllerBase<IViewBase>)).ImplementedBy(typeof(ControllerBase<IViewBase>)).LifeStyle.Transient);
接下来我有从 ControllerBase 派生的类
using System;
namespace HardwareConnections
{
public class HardwareConnectionsController : Controller.ControllerBase<IHardwareConnections>
{
public HardwareConnectionsController(IHardwareConnections view) : base(view)
{
base.ModuleName = "Hardware connections";
Console.WriteLine("\n\n\n\n");
Console.WriteLine("Constructor fired");
Console.WriteLine("\n\n\n\n");
}
}
}
我正在尝试通过首先解析实现 IViewBase 接口的 View 类来解析 HardwareConnectionsController,这工作正常,我正在获取 View 的实例并将其传递给构造函数
但我在解析控制器类时遇到问题
var hcon = container.Resolve<ControllerBase<IViewBase>>(new { view = plug});
错误是:
Castle.MicroKernel.ComponentNotFoundException has been throwed No component for support the service PETController.ControllerBase`1[[PETController.IViewBase, PETController, Version=1.0.4988.28227, Culture=neutral, PublicKeyToken=null]] 堆栈:
Castle.MicroKernel.ComponentNotFoundException: No component for supporting the service PETController.ControllerBase`1[[PETController.IViewBase, PETController, Version=1.0.4988.28227, Culture=neutral, PublicKeyToken=null]] was found
at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve (System.Type service, IDictionary arguments, IReleasePolicy policy) [0x00000] in <filename unknown>:0
at Castle.MicroKernel.DefaultKernel.Resolve (System.Type service, IDictionary arguments) [0x00000] in <filename unknown>:0
at Castle.Windsor.WindsorContainer.Resolve[ControllerBase`1] (System.Object argumentsAsAnonymousType) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) Castle.Windsor.WindsorContainer:Resolve (object)
at PETController.PluginFactory.LoadPlugins[IViewBase] (System.String searchLocation) [0x001f6] in /home/konrad/hg/PET/PET/PETController/Utils/PluginFactory.cs:67
at MainWindow..ctor () [0x00034] in /home/konrad/hg/PET/PET/PETController/MainWindow.cs:19
at PETController.MainClass.Main (System.String[] args) [0x00005] in /home/konrad/hg/PET/PET/PETController/Main.cs:11
enter code here