ActionResult from uncontrolled classes

I decided that my controllers were a bit confused and decided to adopt a pipeline-style system, as I used in the WebAPI project. The conveyor consists of actions that are becoming more and more common, i.e. ViewAccountDetailsAction> AccountAction> AuthenticatedAction> EmptyAction. Actions are also added to pipleline in order of inheritance, and also expose elements or abstract methods for different scenarios.

My problem is how to return views from pipeline elements. In the WebAPI example, it was as simple as returning IHttpActionResult, which should not have done any kind of rendering, however MVC is required to work out its answers differently, with an additional Razor step.

Since controllers reveal internal protectedhelper methods such as View()or RedirectToAction, I cannot use them outside the controllers themselves.

Is there an elegant way to do this? I saw several ways to do this, each of which was either cumbersome or gave me uncomfortable feelings.

My most preferred way at the moment is to create a base class internalthat hides protected methods and makes them internal, and calls the base methods. Then the controller instance will be provided to create the instance. Is there anything too bad in this regard? I cannot think of any abuses, but I would like to know if there is any community consensus on this issue.

+4
source share
1 answer

I would recommend taking your approach even further.

It took a bit of research, but I based it on the approach I did for the client with Web API 2. The main idea was to create a custom ControllerSelector, ActionSelector and ActionDescriptors and a base controller class that showed a strong typed business layer. Then, using reflexive / user attributes, we streamlined the business layer call by handling the transformations in the HttpResponseResponse message as a whole, including errors.

, , : http://www.dotnet-tricks.com/Tutorial/mvc/LYHK270114-Detailed-ASP.NET-MVC-Pipeline.html

, ASP.NET MVC5 , -API 2. :

, , , , . .

/ , , , , , . !

+1

Source: https://habr.com/ru/post/1620681/


All Articles