有什么方法可以使用类而不继承ApiController并用作api控制器? [英] Is there any way to use class without inheriting from ApiController, use as api controller?

查看:107
本文介绍了有什么方法可以使用类而不继承ApiController并用作api控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ASP.NET Boilerplate 中知道了所需的解决方案.在此框架中,您可以声明类,从自定义类继承(而不是从ApiController继承),并且在其运行时,它会构建控制器并像控制器​​一样工作.

I know solution like I want in ASP.NET Boilerplate. In this framework you can declare classes, inherit from custom class ( not inherited from ApiController ) and when it's run, it builds controllers and works like controllers.

但是我从头开始编写我的应用程序,实际上我不知道它如何在Boilerplate中工作(我认为它使用重构,我发现了ControllerBuilder类,但是它是如此大的库,我认为重写它不是一个好主意相同的代码或复制过去,有太多的依赖项).

But I write my application from scratch and actually I don't know how it works in Boilerplate ( I think it use refactoring, I found ControllerBuilder classes, but it's so big library, I don't think it's good idea to rewrite same code or copy past it, there are so many dependencies ).

我知道我可以使用自定义类方法处理请求和响应,但是我认为它会有点缓慢且不安全.

I know I can handle requests and response with my custom classes methods, but I think it will work a little bit slowly and not safely.

也许您知道一种简单的方法?谢谢你.

Maybe you know a simple way to do it? Thank you.

推荐答案

您要问的是技术上可行的,但绝不是那么简单.实际上,如果您对此一无所知,我建议您可能根本不想使用Web-Api框架.

What you are asking is technically possible but in no way would it be simple. In fact, if you are dead set on this I would suggest that you may not want to use the Web-Api framework at all.

但是,为了解决可能出现的问题,我将从着眼于利用 HttpRoutingDispatcher 作为扩展点开始.可以在此处找到包括调度程序在内的管道的概述:http://byterot.blogspot.com/2012/05/aspnet-web-api-series-messagehandler.html

However, to address the question of being possible, I would start by looking at leveraging HttpRoutingDispatcher as an extension point. An overview of the pipeline including the dispatcher can be found here: http://byterot.blogspot.com/2012/05/aspnet-web-api-series-messagehandler.html

一旦找到合适的位置来扩展Web api管道,您仍将需要创建一个组件,该组件将以某种方式知道"如何调用非控制器-并且您将失去大部分框架必须提供的内容(动作解析,参数绑定,动作过滤器等​​)

Once you come up with the right place to extend the web api pipeline, you will still need to create the component(s) which will somehow "know" how to invoke your non-controllers - and you will be losing most of what the framework has to offer (action resolution, parameter binding, action filters, etc.)

这篇关于有什么方法可以使用类而不继承ApiController并用作api控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆