我有一个标题上所述的问题。我正在将Ninject用作依赖项注入和我的服务定位器,如下所示:
IEnumarable<Address>
我在我的类ErrorService类中使用了ServiceLocator,如下所示:
internal class ServiceLocator
{
private static readonly IServiceLocator _serviceLocator;
static ServiceLocator()
{
_serviceLocator = new DefaultServiceLocator();
}
public static IServiceLocator Current
{
get
{
return _serviceLocator;
}
}
private class DefaultServiceLocator : IServiceLocator
{
private readonly IKernel kernel; // Ninject kernel
public DefaultServiceLocator()
{
kernel = new StandardKernel();
LoadBindings();
}
public T Get<T>()
{
try
{
return kernel.Get<T>();
}
catch (Exception hata)
{
throw hata;
}
}
private void LoadBindings()
{
kernel.Bind<IErrorDal>().To<ErrorDal>().InSingletonScope().WithConstructorArgument("connectionString", "myConnectionString");
kernel.Bind<IErrorBusinessRule>().To<ErrorBusinessRule>().InSingletonScope();
kernel.Bind<IApplicationBusinessRule>().To<ApplicationBusinessRule>().InSingletonScope();
kernel.Bind<ControlService>().To<ControlService>().InSingletonScope();
}
}
}
我在行中找到了System.TypeLoadException
this._errorBusinessRule = ServiceLocator.Current.Get();
“无法从程序集“ mscorlib”加载类型“ System.Runtime.Remoting.RemotingServices”,
答案 0 :(得分:0)
经过调查,我指出我的测试项目类型是MsTest测试项目。 (.Net Core)当我选择单元测试项目(.NET Framework)时,问题已解决。