0
我是一个对接口进行编码的巨大粉丝。在WCF世界中,这强调了每项服务。然而,我深入了解ASP.NET Web Api,作为MVC 4的扩展,我很好奇,看看是否有一些典型的推理让你的控制器实现从接口继承。asp.net web api控制器接口有什么好处吗?
我知道ASP.NET网页API的默认设置是这个样子
public class TestsController : ApiController
{
public IEnumerable<string> Get()
{
var testValues = new List<string>
{
"Something",
"Welcome to the top of the world"
};
return testValues;
}
}
与此相反用cooresponding接口(或接口)。
public class TestsController : ApiController, ITestsController
{
public IEnumerable<string> Get()
{
var testValues = new List<string>
{
"Something",
"Welcome to the top of the world"
};
return testValues;
}
}
这就是我想的。在这个框架中,我看不出很多使用紧密编程控制器的接口,特别是因为对象以JSON的形式离开和输入服务(通常),并且在HTTP环境中。我想这个概念放弃了依靠彼此的前向型安全和有限合同的单独程序集的想法。 – 2013-03-14 14:32:07