{"id":482288,"date":"2026-06-03T17:10:24","date_gmt":"2026-06-03T17:10:24","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=482288"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=482288","title":{"rendered":"redb.Route 3.0.1 \u2014 \u043f\u043b\u043e\u0441\u043a\u0430\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043f\u043e DSL, \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 CRTP \u0438 \u0442\u0438\u0445\u0438\u0439 null"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0441\u0435\u0440\u0438\u044e \u043f\u0440\u043e redb.Route \u2014\u00a0<a href=\"https:\/\/habr.com\/ru\/articles\/1042392\/\" rel=\"noopener noreferrer nofollow\">\u0432\u0432\u043e\u0434\u043d\u0430\u044f<\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/habr.com\/ru\/articles\/1042872\/\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0437\u0431\u043e\u0440 \u0447\u0435\u0442\u044b\u0440\u0451\u0445 in-memory \u043a\u0430\u043d\u0430\u043b\u043e\u0432<\/a>\u00a0\u0443\u0436\u0435 \u0432\u044b\u0448\u043b\u0438. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043d\u0435 \u0441\u0442\u0430\u0442\u044c\u044f \u0441\u0435\u0440\u0438\u0438, \u0430 \u0440\u0435\u043b\u0438\u0437\u043d\u0430\u044f \u0437\u0430\u043c\u0435\u0442\u043a\u0430: \u0432 3.0.1 \u0442\u0440\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 DSL, \u043a\u0430\u0436\u0434\u043e\u0435 \u0441 \u0431\u043e\u0435\u0432\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0438\u0437 \u0434\u0435\u043c\u043e.<\/p>\n<p>\u0414\u043e 3.0.1 \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 scope-\u044b \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u044f \u0432 \u0441\u0442\u0440\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u2014 \u0443\u0442\u043e\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438 \u043b\u0435\u0433\u043a\u043e \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f. \u0422\u0440\u0438 \u0432\u0435\u0449\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c.<\/p>\n<hr\/>\n<h3>\u041f\u043b\u043e\u0441\u043a\u0430\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437\u00a0End*()<\/h3>\n<p>Typed-closer \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0434\u0451\u0442 \u0432\u0432\u0435\u0440\u0445 \u043f\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0435\u00a0<code>Parent<\/code>\u00a0\u0438 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0437\u0430 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432:<\/p>\n<pre><code>From(\"direct:\/\/demo-cascade-endchoice\")    .Choice()        .When(e =&gt; true)            .Split(e =&gt; new object?[] { 1, 2, 3 })                .Process(e =&gt; { \/* \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c *\/ })                .Log(\"item=${body}\")            .EndChoice()   \/\/ \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043c\u0438\u043c\u043e Split \u2192 When \u2192 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u0440\u0435\u043d\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430    .SetHeader(\"post-cascade\", \"ok\")    .Log(\"\u043a\u0430\u0441\u043a\u0430\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043d\");<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439\u00a0<code>.End()<\/code>\u00a0\u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043a \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c\u0443 scope, \u043d\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u044f \u0435\u0433\u043e:<\/p>\n<pre><code>.Choice()    .When(e =&gt; true)        .Split(e =&gt; new object?[] { \"a\", \"b\" })            .Log(LogLevel.Information)                .Message(\"inside\")            .End()   \/\/ \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 RichLog \u2192 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043b\u043e Split        .End()        \/\/ \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 Split   \u2192 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043b\u043e When    .EndChoice()      \/\/ \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 Choice  \u2192 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u0440\u0435\u043d\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0421\u043e\u0441\u0435\u0434\u043d\u0438\u0435 \u0432\u0435\u0442\u043a\u0438 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e sub-scope \u2014\u00a0<code>.When()<\/code>\u00a0\u0438\u00a0<code>.Otherwise()<\/code>\u00a0\u043a\u0430\u043a extension methods \u043d\u0430\u0445\u043e\u0434\u044f\u0442 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439\u00a0<code>ChoiceDefinition<\/code>\u00a0\u0447\u0435\u0440\u0435\u0437\u00a0<code>Parent<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0435\u0441\u0442\u044c:<\/p>\n<pre><code>.Choice()    .When(e =&gt; e.In.Body is IEnumerable&lt;string&gt; &amp;&amp; e.In.Body is not string)        .Split(...)            .Process(...)        .EndSplit()        .Log(\"\u0432\u0435\u0442\u043a\u0430 list \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 [${routeId}]\")   \/\/ \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0430 \u0442\u0435\u043b\u0435 When, \u043d\u0435 \u043d\u0430 Split    .When(e =&gt; e.In.Body is string s &amp;&amp; s.Length &gt; 0)   \/\/ \u2190 \u0441\u043e\u0441\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u0442\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 EndSplit        .Process(e =&gt; { \/* ... *\/ })    .Otherwise()        .Process(e =&gt; { \/* fallback *\/ }).EndChoice()<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<hr\/>\n<h3>\u0422\u0440\u0438 \u0444\u043e\u0440\u043c\u044b \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u0432 \u043e\u0434\u043d\u043e\u043c pipeline-\u0448\u0430\u0433\u0435<\/h3>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u043e\u0435 \u0434\u0435\u043c\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0442\u0440\u0438 \u0440\u044f\u0434\u043e\u043c \u2014 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0433\u0434\u0435 \u0447\u0442\u043e \u0443\u043c\u0435\u0441\u0442\u043d\u043e:<\/p>\n<pre><code>\/\/ (A) \u041b\u044f\u043c\u0431\u0434\u0430 \u2014 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 C# \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435.Log(e =&gt; $\"[lambda] item={e.In.Body} branch={e.In.Headers[\"branch\"]}\")\/\/ (B) \u0421\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u2014 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f expression-\u0434\u0432\u0438\u0436\u043a\u043e\u043c,\/\/     \u043d\u043e\u043b\u044c \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u043a\u043e\u0433\u0434\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d.Log(\"[tmpl] item=${body} branch=${header.branch} [${routeId}]\")\/\/ (C) Rich-log scope \u2014 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439,\/\/     \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432\u044b\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f.Log(LogLevel.Information)    .Message(\"[rich-tmpl]   item=${body}\")    .Message(e =&gt; $\"[rich-lambda] upper={((string)e.In.Body!).ToUpperInvariant()}\")    .Header(\"branch\")    .Property(\"item-index\")    .ShowRouteId(true).EndLog()<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p><code>${body}<\/code>,\u00a0<code>${header.x}<\/code>,\u00a0<code>${property.y}<\/code>,\u00a0<code>${routeId}<\/code>,\u00a0<code>${exception.type}<\/code>,\u00a0<code>${exception.message}<\/code>\u00a0\u2014 \u0432\u0441\u0451 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c expression-\u0434\u0432\u0438\u0436\u043a\u043e\u043c (Tokenizer \u2192 Parser \u2192 AST \u2192 IL). \u0428\u0430\u0431\u043b\u043e\u043d \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0434\u0430\u043b\u044c\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0437\u0430\u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0434\u0435\u043b\u0435\u0433\u0430\u0442.\u00a0<code>.Message()<\/code>\u00a0\u0432 rich-log scope \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0431\u0435 \u0444\u043e\u0440\u043c\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/p>\n<p>\u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 catch-\u0431\u043b\u043e\u043a\u0430:<\/p>\n<pre><code>.TryCatch()    .Process(e =&gt; throw new InvalidOperationException(\"boom\")).DoCatch&lt;InvalidOperationException&gt;()    .Log(\"[tmpl] caught: ${exception.type} \u2014 ${exception.message} [${routeId}]\")    .Log(LogLevel.Warning)        .Message(e =&gt; $\"[lambda] stack: {e.Exception?.StackTrace?.Split('\\n').First().Trim()}\")        .ShowRouteId(true)    .EndLog().EndTryCatch()<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<hr\/>\n<h3>CRTP-\u0431\u0430\u0437\u0430 \u2014 \u0443\u0434\u0430\u043b\u0435\u043d\u043e 27 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u0442\u0435\u043b \u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h3>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 leaf-\u043c\u0435\u0442\u043e\u0434 (<code>To<\/code>,\u00a0<code>Process<\/code>,\u00a0<code>SetBody<\/code>,\u00a0<code>Filter<\/code>,\u00a0<code>Split<\/code>,\u00a0<code>Transaction<\/code>, ~40 \u0448\u0442\u0443\u043a) \u0440\u0430\u043d\u044c\u0448\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 scope-\u043a\u043b\u0430\u0441\u0441. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u043e\u043d\u0438 \u0436\u0438\u0432\u0443\u0442 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0432\u00a0<code>RouteDefinitionBase&lt;TSelf&gt;<\/code>. \u041a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u00a0<code>TSelf<\/code>\u00a0\u2014 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0442\u0438\u043f\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e scope. \u041f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 API \u0438 AST \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b 3.0.0. \u0427\u0438\u0441\u0442\u044b\u0439 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u2014 \u043d\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u043b\u043e\u0441\u043a\u0443\u044e \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044e \u0432\u044b\u0448\u0435.<\/p>\n<hr\/>\n<h3>\u0424\u0438\u043a\u0441:\u00a0GetContext()\u00a0\u0442\u0438\u0445\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b null \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 scope-\u043e\u0432<\/h3>\n<p><code>IRouteDefinition.GetContext()<\/code>\u00a0\u0434\u0435\u043b\u0430\u043b cast \u043a\u00a0<code>RouteDefinition<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043a\u043e\u0440\u043d\u0435\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430. \u0412\u043d\u0443\u0442\u0440\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e scope \u2014\u00a0<code>When<\/code>,\u00a0<code>Loop<\/code>,\u00a0<code>Traced<\/code>,\u00a0<code>Catch<\/code>\u00a0\u2014 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u00a0<code>null<\/code>\u00a0\u0431\u0435\u0437 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043d \u0438\u0434\u0451\u0442 \u0432\u0432\u0435\u0440\u0445 \u043f\u043e\u00a0<code>Parent<\/code>\u00a0\u0434\u043e owning-\u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430. \u0412\u0430\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c extension methods, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0438\u0442\u0430\u044e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f DSL.<\/p>\n<hr\/>\n<p>\u041f\u043e\u043b\u043d\u043e\u0435 \u0434\u0435\u043c\u043e \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u2014\u00a0<a href=\"https:\/\/github.com\/redbase-app\/redb-route\/blob\/main\/redb.Route.Demo\/Routes\/DeepDslShowcaseRoutes.cs\" rel=\"noopener noreferrer nofollow\">DeepDslShowcaseRoutes.cs<\/a>. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u2014 \u0432\u00a0<a href=\"http:\/\/CHANGELOG.md\" rel=\"noopener noreferrer nofollow\">CHANGELOG.md<\/a>. \u0412\u0441\u0451 \u043f\u043e\u0434 Apache 2.0.<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1043332\/\">https:\/\/habr.com\/ru\/articles\/1043332\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0441\u0435\u0440\u0438\u044e \u043f\u0440\u043e redb.Route \u2014\u00a0\u0432\u0432\u043e\u0434\u043d\u0430\u044f\u00a0\u0438\u00a0\u0440\u0430\u0437\u0431\u043e\u0440 \u0447\u0435\u0442\u044b\u0440\u0451\u0445 in-memory \u043a\u0430\u043d\u0430\u043b\u043e\u0432\u00a0\u0443\u0436\u0435 \u0432\u044b\u0448\u043b\u0438. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043d\u0435 \u0441\u0442\u0430\u0442\u044c\u044f \u0441\u0435\u0440\u0438\u0438, \u0430 \u0440\u0435\u043b\u0438\u0437\u043d\u0430\u044f \u0437\u0430\u043c\u0435\u0442\u043a\u0430: \u0432 3.0.1 \u0442\u0440\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 DSL, \u043a\u0430\u0436\u0434\u043e\u0435 \u0441 \u0431\u043e\u0435\u0432\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0438\u0437 \u0434\u0435\u043c\u043e.\u0414\u043e 3.0.1 \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 scope-\u044b \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u044f \u0432 \u0441\u0442\u0440\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u2014 \u0443\u0442\u043e\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438 \u043b\u0435\u0433\u043a\u043e \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f. \u0422\u0440\u0438 \u0432\u0435\u0449\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c.\u041f\u043b\u043e\u0441\u043a\u0430\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437\u00a0End*()Typed-closer \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0434\u0451\u0442 \u0432\u0432\u0435\u0440\u0445 \u043f\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0435\u00a0Parent\u00a0\u0438 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0437\u0430 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432:From(&#171;direct:\/\/demo-cascade-endchoice&#187;)    .Choice()        .When(e =&gt; true)            .Split(e =&gt; new object?[] { 1, 2, 3 })                .Process(e =&gt; { \/* \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c *\/ })                .Log(&#171;item=${body}&#187;)            .EndChoice()   \/\/ \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043c\u0438\u043c\u043e Split \u2192 When \u2192 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u0440\u0435\u043d\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430    .SetHeader(&#171;post-cascade&#187;, &#171;ok&#187;)    .Log(&#171;\u043a\u0430\u0441\u043a\u0430\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043d&#187;);\u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439\u00a0.End()\u00a0\u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043a \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c\u0443 scope, \u043d\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u044f \u0435\u0433\u043e:.Choice()    .When(e =&gt; true)        .Split(e =&gt; new object?[] { &#171;a&#187;, &#171;b&#187; })            .Log(LogLevel.Information)                .Message(&#171;inside&#187;)            .End()   \/\/ \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 RichLog \u2192 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043b\u043e Split        .End()        \/\/ \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 Split   \u2192 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043b\u043e When    .EndChoice()      \/\/ \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 Choice  \u2192 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u0440\u0435\u043d\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430\u0421\u043e\u0441\u0435\u0434\u043d\u0438\u0435 \u0432\u0435\u0442\u043a\u0438 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e sub-scope \u2014\u00a0.When()\u00a0\u0438\u00a0.Otherwise()\u00a0\u043a\u0430\u043a extension methods \u043d\u0430\u0445\u043e\u0434\u044f\u0442 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439\u00a0ChoiceDefinition\u00a0\u0447\u0435\u0440\u0435\u0437\u00a0Parent, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0435\u0441\u0442\u044c:.Choice()    .When(e =&gt; e.In.Body is IEnumerable&lt;string&gt; &amp;&amp; e.In.Body is not string)        .Split(&#8230;)            .Process(&#8230;)        .EndSplit()        .Log(&#171;\u0432\u0435\u0442\u043a\u0430 list \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 [${routeId}]&#187;)   \/\/ \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0430 \u0442\u0435\u043b\u0435 When, \u043d\u0435 \u043d\u0430 Split    .When(e =&gt; e.In.Body is string s &amp;&amp; s.Length &gt; 0)   \/\/ \u2190 \u0441\u043e\u0441\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u0442\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 EndSplit        .Process(e =&gt; { \/* &#8230; *\/ })    .Otherwise()        .Process(e =&gt; { \/* fallback *\/ }).EndChoice()\u0422\u0440\u0438 \u0444\u043e\u0440\u043c\u044b \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u0432 \u043e\u0434\u043d\u043e\u043c pipeline-\u0448\u0430\u0433\u0435\u041e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u043e\u0435 \u0434\u0435\u043c\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0442\u0440\u0438 \u0440\u044f\u0434\u043e\u043c \u2014 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0433\u0434\u0435 \u0447\u0442\u043e \u0443\u043c\u0435\u0441\u0442\u043d\u043e:\/\/ (A) \u041b\u044f\u043c\u0431\u0434\u0430 \u2014 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 C# \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435.Log(e =&gt; $&#187;[lambda] item={e.In.Body} branch={e.In.Headers[&#171;branch&#187;]}&#187;)\/\/ (B) \u0421\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u2014 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f expression-\u0434\u0432\u0438\u0436\u043a\u043e\u043c,\/\/     \u043d\u043e\u043b\u044c \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u043a\u043e\u0433\u0434\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d.Log(&#171;[tmpl] item=${body} branch=${header.branch} [${routeId}]&#187;)\/\/ (C) Rich-log scope \u2014 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439,\/\/     \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432\u044b\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f.Log(LogLevel.Information)    .Message(&#171;[rich-tmpl]   item=${body}&#187;)    .Message(e =&gt; $&#187;[rich-lambda] upper={((string)e.In.Body!).ToUpperInvariant()}&#187;)    .Header(&#171;branch&#187;)    .Property(&#171;item-index&#187;)    .ShowRouteId(true).EndLog()${body},\u00a0${header.x},\u00a0${property.y},\u00a0${routeId},\u00a0${exception.type},\u00a0${exception.message}\u00a0\u2014 \u0432\u0441\u0451 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c expression-\u0434\u0432\u0438\u0436\u043a\u043e\u043c (Tokenizer \u2192 Parser \u2192 AST \u2192 IL). \u0428\u0430\u0431\u043b\u043e\u043d \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0434\u0430\u043b\u044c\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0437\u0430\u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0434\u0435\u043b\u0435\u0433\u0430\u0442.\u00a0.Message()\u00a0\u0432 rich-log scope \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0431\u0435 \u0444\u043e\u0440\u043c\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.\u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 catch-\u0431\u043b\u043e\u043a\u0430:.TryCatch()    .Process(e =&gt; throw new InvalidOperationException(&#171;boom&#187;)).DoCatch&lt;InvalidOperationException&gt;()    .Log(&#171;[tmpl] caught: ${exception.type} \u2014 ${exception.message} [${routeId}]&#187;)    .Log(LogLevel.Warning)        .Message(e =&gt; $&#187;[lambda] stack: {e.Exception?.StackTrace?.Split(&#8216;\\n&#8217;).First().Trim()}&#187;)        .ShowRouteId(true)    .EndLog().EndTryCatch()CRTP-\u0431\u0430\u0437\u0430 \u2014 \u0443\u0434\u0430\u043b\u0435\u043d\u043e 27 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u0442\u0435\u043b \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u041a\u0430\u0436\u0434\u044b\u0439 leaf-\u043c\u0435\u0442\u043e\u0434 (To,\u00a0Process,\u00a0SetBody,\u00a0Filter,\u00a0Split,\u00a0Transaction, ~40 \u0448\u0442\u0443\u043a) \u0440\u0430\u043d\u044c\u0448\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 scope-\u043a\u043b\u0430\u0441\u0441. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u043e\u043d\u0438 \u0436\u0438\u0432\u0443\u0442 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0432\u00a0RouteDefinitionBase&lt;TSelf&gt;. \u041a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u00a0TSelf\u00a0\u2014 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0442\u0438\u043f\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e scope. \u041f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 API \u0438 AST \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b 3.0.0. \u0427\u0438\u0441\u0442\u044b\u0439 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u2014 \u043d\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u043b\u043e\u0441\u043a\u0443\u044e \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044e \u0432\u044b\u0448\u0435.\u0424\u0438\u043a\u0441:\u00a0GetContext()\u00a0\u0442\u0438\u0445\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b null \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 scope-\u043e\u0432IRouteDefinition.GetContext()\u00a0\u0434\u0435\u043b\u0430\u043b cast \u043a\u00a0RouteDefinition, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043a\u043e\u0440\u043d\u0435\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430. \u0412\u043d\u0443\u0442\u0440\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e scope \u2014\u00a0When,\u00a0Loop,\u00a0Traced,\u00a0Catch\u00a0\u2014 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u00a0null\u00a0\u0431\u0435\u0437 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043d \u0438\u0434\u0451\u0442 \u0432\u0432\u0435\u0440\u0445 \u043f\u043e\u00a0Parent\u00a0\u0434\u043e owning-\u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430. \u0412\u0430\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c extension methods, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0438\u0442\u0430\u044e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f DSL.\u041f\u043e\u043b\u043d\u043e\u0435 \u0434\u0435\u043c\u043e \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u2014\u00a0DeepDslShowcaseRoutes.cs. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u2014 \u0432\u00a0CHANGELOG.md. \u0412\u0441\u0451 \u043f\u043e\u0434 Apache 2.0.\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1043332\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-482288","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/482288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=482288"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/482288\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=482288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=482288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=482288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}