モデルビューディスパッチャー(mvc上のcqrs)

画像

この記事では、Incoding Frameworkライブラリの別のコンポーネントを強調したいと思います。
モデルビューディスパッチャー(MVD) -冗長コード(つまり、asp.net mvcコントローラー)を取り除き、クライアントとサーバーのコード間の抽象化の数を減らすことでプロジェクトのナビゲーションを簡素化します。

Habréには、フレームワークの一部であるIMLおよびCQRSに関するいくつかの記事があります
  1. IMLの紹介
  2. CQRSのコーディング
    注:記事は公開されましたが、その時点でHabréのアカウントに問題があり、気付かずに通過しました
  3. IMLとAngularJs
    注:記事は批判されました(客観的および主観的)
  4. IMl対AngularJsへの返信
    注:成功とは言えませんが、もう少し良いです

MVDはいくつかの記事に登場しましたが、IMLの機能を示す例の一部として、それについて個別に話をすることを決めましたが、順番にすべてについて...

なんで?


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/J221585/


All Articles