📜 ⬆️ ⬇️

Model View Dispatcher (cqrs over mvc)

image

Good all the time of day, in this article I want to highlight another component of the library Incoding Framework.
Model View Dispatcher (MVD) - allows you to get rid of redundant code (namely, asp.net mvc controller) and simplify project navigation, reducing the number of abstractions between client and server code.

Habré has several articles on IML and CQRS , which are part of the framework
  1. Introducing IML
  2. Incoding CQRS
    note: the article was published, but at that time there were problems with the account on the habr and it passed unnoticed
  3. IML vs AngularJs
    note: the article has been criticized (objective and subjective)
  4. IMl vs AngularJs Response
    note: can not be called a success, but a little better

MVD appeared in some articles, but as part of an example demonstrating the capabilities of IML, so I decided to tell about it separately, but first things first ...

What for?


Consider a scenario using asp.net mvc + cqrs

: Query , Action


controller «» Mediator ( ), Interface Generic, , , Controller/Action.

Model View Dispatcher (MVD) — Command/Query «» asp.net mvc. , MVD
$.get('@Url.Dispatcher().Query(new GetUserDetailsQuery()).AsJson()',callback)




MVC ???


, MVD :

DispatcherController ( 1.1 nuget), DispatcherControllerBase
public class DispatcherController : DispatcherControllerBase
{        
    public DispatcherController()
   : base(typeof(T).Assembly)
    {    }    
}

: Assembly Command/Query

DispatcherControllerBase (Actions):
Query(string incType, string incGeneric, bool? incValidate)
Render(string incView, string incType, string incGeneric)
Push(string incType, string incGeneric)
Composite(string incTypes)
QueryToFile(string incType, string incGeneric, string incContentType, string incFileDownloadName)

url, Push command
Url.Action("Push", "Dispatcher", new  { incType = typeof(Command).Name } )

DSL (domain specific language)
Url.Dispatcher().Push(new Command())

: ( ), ( ..)




: MVD asp.net mvc, ( generic) Controller, httphandler http .

?


MVD , - asp.net mvc:
: GitHub


MVD DispatcherController ( ), CQRS Command/Query Url.Dispatcher ( , ) url, , IML.

: Inc-todo

Action Attributes


(-́ ‎), , , :


Incoding Framework ( js framework Server/Client ) MVD .
@(using(Html.When(JqueryBind.InitIncoding)      
                         .Direct()
                         .OnSuccess(dsl => dsl.Self().Core().Form.Validation.Parse())
                         .When(JqueryBind.Submit)
                         .PreventDefault()
                         .Submit()
                         .OnError(dsl => dsl.Self().Core().Form.Validation.Refresh())
                         .AsHtmlAttributes()
                         .ToBeginForm(Url.Dispatcher().Push(new AddUserCommand()))))
{
 @Html.TextBoxFor(r=>r.Name)
 @Html.ValidationMessageFor(r=>r.Name)
}

: , html helper
asp.net mvc Html.BeginForm ( iml html attributes), :


, Validation.Refresh Push dispatcher contoller
     if (!ModelState.IsValid)
        return IncodingResult.Error(ModelState)

     try
     {
         dispatcher.Push(composite);
         return IncodingResult.Success();
      }
      catch (IncWebException exception)
      {
                foreach (var pairError in exception.Errors)
                {
                    foreach (var errorMessage in pairError.Value)
                        ModelState.AddModelError(pairError.Key, errorMessage);
                }
                return IncodingResult.Error(ModelState)
      }

: - , Incoding Framework TryPush MVD push
catch IncWebException ( ModelState), exception global.asax.

?

, Incoding Framework , asp.net mvc
public ActionResult Add(AddUserCommand command)
{
    if (ModelState.IsValid)
        return View(command);

    return Execute(command);
}

ModelState , View, command (, Container , ), . :



MVD Action, «» , . MVD IML, Selector routes, , - , «» (pure js) .
, MVD ( ) , Controller Action ( 5% — 10%) .

, ?


MVD 10-15% , , end point ( wcf endpoint)…

, ?

api :


, mvd end-points


: , , , , .


: , API . , , , , - , .

P.S. ( beta) Incoding Framework nuget, . , ( bugtracker)

: beta ( ) , ,

')

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


All Articles