Asp.net Webapi 2依赖项注入导致错误 [英] Asp.net webapi 2 dependency injection giving error that
本文介绍了Asp.net Webapi 2依赖项注入导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用统一容器通过以下代码通过属性进行依赖度注入
Hi I am using unity container for depency injection by attributes using following code
container.RegisterTypes(
AllClasses.FromLoadedAssemblies()
.Where(t => t.GetCustomAttributes<abcAttribute>(true).Any()),
WithMappings.FromMatchingInterface,
WithName.Default,
WithLifetime.PerThread);
问题是有时我会遵循以下异常,如果我清理并重建解决方案,该异常将会发生.我想念什么吗?
Problem is sometimes i get following exception which goes if i clean and rebuild the solution. am i missing something ?
An error occurred when trying to create a controller of type ''ABCController''. Make sure that the controller has a parameterless public constructor.","ExceptionType":"System.InvalidOperationException
我尝试过的事情:
What I have tried:
tried creating parameterless constructor but again get same exception. the exception does not occur when solution is cleaned and build for the first time
<pre>public ABCController()
{
}
推荐答案
报价:
问题有时是我遇到以下异常如果我清洁并重建解决方案,该去.我错过了什么吗?
Problem is sometimes i get following exception which goes if i clean and rebuild the solution. am i missing something ?
是的.您错过了另一个清理和重建的工作.
Yes. You''re missing another clean and rebuild.
这篇关于Asp.net Webapi 2依赖项注入导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文