この記事では、Incoding Frameworkライブラリの別のコンポーネントを強調したいと思います。
モデルビューディスパッチャー(MVD) -冗長コード(つまり、asp.net mvcコントローラー)を取り除き、クライアントとサーバーのコード間の抽象化の数を減らすことでプロジェクトのナビゲーションを簡素化します。
Habréには、フレームワークの一部であるIMLおよびCQRSに関するいくつかの記事があります
- IMLの紹介
- CQRSのコーディング
注:記事は公開されましたが、その時点でHabréのアカウントに問題があり、気付かずに通過しました
- IMLとAngularJs
注:記事は批判されました(客観的および主観的)
- IMl対AngularJsへの返信
注:成功とは言えませんが、もう少し良いです
MVDはいくつかの記事に登場しましたが、IMLの機能を示す例の一部として、それについて個別に話をすることを決めましたが、順番にすべてについて...
なんで?
asp.net mvc + cqrsアプリケーションシナリオを検討する
- コントローラー
public ActionResult Details(GetUserDetailsQuery query) { var model = dispatcher.Query(query); return Json(model); }
: action binding query Dispatcher Json
- View
$.get('@Url.Action("Details","Controller")',callback)
: 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)
- Action
- , (go to delcaration )
- URL (visual studio intelisence, refactor utilities)
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 IDispatcher, IoCFactory ( StructureMap )
- ActionResult IncodingResult, JSON
{ success: true/false , data:something/null , redirectTo:url/null }
: MVD asp.net mvc, ( generic) Controller, httphandler http .
?
MVD , - asp.net mvc:
: GitHub
- Push
Url.Dispatcher().Push(new AddUserCommand { Id = "59140B31-8BB2-49BA-AE52-368680D5418A", Name = "Vlad" })
:
- Push generic
Url.Dispatcher().Push(new AddEntityCommand<T>())
- omposite
Url.Dispatcher() .Push(new AddUserCommand { Id = "1", Name = "Name" }) .Push(new ApproveUserCommand { UserId = "2" })
- Query as json
Url.Dispatcher() .Query(new GetCurrentDtQuery()) .AsJson()
- Query generic
Url.Dispatcher() .Query(new GetTypeNameQuery<T>()) .AsJson()
- Query as view
Url.Dispatcher() .Query(new GetUserQuery()) .AsView("~/Views/Home/User.cshtml")
: View ( asp.net mvc Controller) , .
- Query as file
<a href="@Url.Dispatcher().Query(new GetFileQuery()).AsFile(incFileDownloadName: "framework")">Download</a>
: QueryBase<byte[]> Query
- Model as view
Url.Dispatcher() .Model(new GetUserQuery.Response { Id = "2", Name = "Incoding Framework" }) .AsView("~/Views/Home/User.cshtml")
- View
Url.Dispatcher().AsView("~/Views/Home/Template.cshtml")
MVD DispatcherController ( ), CQRS Command/Query Url.Dispatcher ( , ) url, , IML.
- Post
@(Html.When(JqueryBind.Change) .AjaxPost(Url.Dispatcher().Push<AddAcoGroupCommand>(new {Value = Selector.Jquery.Self() } )) .OnSuccess(dsl => dsl.Utilities.Window.Alert("Success")) .AsHtmlAttributes() .ToCheckBox(true))
: , ( Value AddAcoGroupCommand exception) .
- Post form
@model AddAcoGroupCommand <form action="@Url.Dispatcher().Push(new AddAcoGroupCommand())"> @Html.HiddenFor(r=>r.Id) <input type="submit"/> </form>
- Render View
@(Html.When(JqueryBind.InitIncoding) .AjaxGet(Url.Dispatcher().AsView("~/Views/Patient/BenefitListControl.cshtml")) .OnSuccess(dsl => dsl.Self().Core().Insert.Html()) .AsHtmlAttributes() .ToDiv())
: template
var urlTmpl = Url.Dispatcher().AsView("~/Views/Medication/MedicationTmpl.cshtml"); dsl.Self().Core().Insert.WithTemplateByUrl(urlTemplate).Append();
- Render model
@(Html.When(JqueryBind.InitIncoding) .AjaxGet(Url.Dispatcher() .Model( new BenefitModel() { GroupName = Selector.Incoding.QueryString<BenefitModel>(r=>r.GroupName), IsPrimary = true }) .AsView("~/Views/Patient/BenefitListControl.cshtml")) .OnSuccess(dsl => dsl.Self().Core().Insert.Html()) .AsHtmlAttributes() .ToDiv())
: Selector ( ) url routes .
: Inc-todo
Action Attributes
(-́ ), , , :
- DispatcherController
: , CRM
- Dispatcher event — Command/Query , Action attributes.
: Action Command/Query
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), :
- Submit ( ) ajax post (Url.Dispatcher().Push(new AddUserCommand())
- (, ) Model State ( )
, 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 , ), . :
- ,
- html ( json), action, API ()
MVD Action, «» , . MVD IML, Selector routes, , - , «» (pure js) .
, MVD ( ) , Controller Action ( 5% — 10%) .
, ?
MVD 10-15% , , end point ( wcf endpoint)…
, ?
api :
- Api — , /GetUsers?Active=true
- Api — user ( Comment, City, State )
- Api — , City /GetCities
- Api — , , State ,
- — , %sitename%-api-%current-version%
: %current-version%, ,
, mvd end-points
- Api —
- — appDomain/Dispatcher/Endpoints?
- Api — , command/query
: , API, UI (user interface) (unit test , ) -
: , , , , .
: , API . , , , , - , .
P.S. ( beta) Incoding Framework nuget, . , ( bugtracker)
-
Break.If(r=>r.Is(()=>Selector.Jquery.Self()).And.Is(()=>"id".ToId()== 12)) // Old Break.If(()=>Selector.Jquery.Self() && id.ToId() == 12) // New
- EF, RavenDB, MongoDb ( command ORM github inc-todo-ravendb)
-
inDsl.Core().JQuery.Attributes.SetAttr(HtmlAttribute.Checked) // Now inDsl.Attr.Set(HtmlAttr.Checked) // Future
: beta ( ) , ,