使用NBear开发时,出现异常!
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
Generic parameter type - IServiceInterfaceType must be an interface implementing NBear.IoC.Service.IServiceInterface or marked with ServiceContractAttribute.
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentException: Generic parameter type - IServiceInterfaceType must be an interface implementing NBear.IoC.Service.IServiceInterface or marked with ServiceContractAttribute.
源错误:
行 23:
行 24: ServiceFactory factory = ServiceFactory.Create();
行 25: IProductService ips = factory.GetService<IProductService>();
在运行时出现这个异常,编译是成功的。我是按照NBear教程的IOC篇一步步做下来的,中间没有遗漏任何东西。上面异常的意思是我没有使用接口参数,但我分明传的是借口啊!!!
以下是NBear项目中,这个该方法的部分代码:
public IServiceInterfaceType GetService<IServiceInterfaceType>()
//where IServiceInterfaceType : IServiceInterface
{
Exception ex = new ArgumentException("Generic parameter type - IServiceInterfaceType must be an interface implementing NBear.IoC.Service.IServiceInterface or marked with ServiceContractAttribute.");
//如果非接口类型,则抛出异常
if (!typeof(IServiceInterfaceType).IsInterface)
{
throw ex;
}
求救!!!