由于 Autofac 不在 Mono 上工作,我正在尝试切换到 Windsor IoC 框架。我想在 dll 中搜索我的接口 IDataLoader 的实现,并将它们全部解析为实例。
这是我的解析代码:
var container = new WindsorContainer();
System.Reflection.Assembly asm = System.Reflection.Assembly.LoadFrom("/home/konrad/DataLoader.dll");
container.Register(AllTypes.FromAssembly(asm));
IDataLoader loader = container.Resolve<IDataLoader>();
界面如下所示:
namespace Viewer.Core.Data
{
public interface IDataLoader
{
PointControl[] GetPositionData(string filePath);
}
}
和实施:
using OpenTK;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Viewer.Core.Data;
using Castle.Windsor;
using Castle.MicroKernel.Registration;
namespace DataLoader
{
public class StandardDataLoader : IDataLoader
{
public StandardDataLoader ()
{
}
public PointControl[] GetPositionData(string filePath)
{
return CreateCloud(filePath);
}
private PointControl[] CreateCloud(string path)
{
//loading data from file code
return points;
}
}
}
解决后我收到错误:
{Castle.MicroKernel.ComponentNotFoundException: No component for supporting the service Viewer.Core.Data.IDataLoader 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[IDataLoader] () [0x00000] in <filename unknown>:0 at (wrapper remoting-invoke-with-check) Castle.Windsor.WindsorContainer:Resolve () at ViewerMultiplatform.DataModel.LoadModel (System.String modelPath) [0x00027] in /home/konrad/hg/ViewerPrototype/OpenTKMultithread/ViewerMultiplatform/Models/DataModel.cs:103 }
为了使我的类可以被 Windsor 框架解析,我是否需要做任何额外的工作?我也尝试使用 register 和 resolveall 方法,但对我没有用。