我是这方面的新手,所以我会尽我所能把这件事说清楚.
我创建了一个WcfModule,在其中加载以下包:
Bind<IDistributorService>().To<DistributorService>().InRequestScope().Intercept().With<ExceptionInterceptor>();起初,我没有收到任何错误,但我在函数中添加了一个InterceptAttribute:
[AttributeUsage(AttributeTargets.Method)]
public sealed class HandleExceptionsAttribute : InterceptAttribute
{
public override IInterceptor CreateInterceptor(IProxyRequest request)
{
return request.Kernel.Get<ExceptionInterceptor>();
}
}
[HandleExceptions]
public virtual Result<List<DistributorDataContract>> GetDistributor(string id)
{
//...code...我在这个函数中得到一个错误:(方法中的第一行)
private ServiceHost CreateNewServiceHost(Type serviceType, Uri[] baseAddresses, WebHttpBehavior webBehavior, WebHttpBinding webHttpBinding)
{
var host = base.CreateServiceHost(serviceType, baseAddresses);
//...
}有错误:
InvalidProxyConstructorArgumentsException未被用户代码处理,无法实例化类的代理: My.Namespace.DistributorService。找不到无参数构造函数。
有谁知道问题可能是什么吗?谢谢!
发布于 2014-09-06 13:25:39
当城堡核心动态代理被指示创建一个“类代理”时,这个异常会被抛出,这个类代理没有无参数的(默认)构造函数,也没有构造函数--参数被传递给城堡(参见来源)。
我的最佳猜测是,当您通过属性使用ninject侦听时,ninject将指示卡斯尔核心创建一个类代理,不管您的绑定是Bind<IFoo>().To<Foo>()还是Bind<Foo>().ToSelf()。
然而,不能解析和传递所有所需的构造函数参数,这似乎有点奇怪。
DistributorService的实现是什么,包含CreateNewServiceHost的类的基类的实现是什么
解决办法:当然,切换到Intercept().With<TInterceptor>()语法也可能使您能够使用拦截(参见http://codepyre.com/2010/03/using-ninject-extensions-interception-part-2-working-with-interceptors/)。
https://stackoverflow.com/questions/25662664
复制相似问题