frontends https://old.t2.sa/en en Micro-frontends with ASP.NET Core MVC https://old.t2.sa/en/blog/Micro-frontends <span>Micro-frontends with ASP.NET Core MVC</span> <span><span>zrik</span></span> <span>Wed, 01/20/2021 - 13:13</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3 class="text-align-justify">What are Micro Frontends?</h3> <p class="text-align-justify">The term Micro Frontends first came up in Thought Works Technology Radar at the end of 2016. It extends the concepts of micro services to the frontend world. The current trend is to build a feature-rich and powerful browser application, aka single page app, which sits on top of a micro service architecture. Over time the frontend layer, often developed by a separate team, grows and gets more difficult to maintain. That’s what we call a Frontend Monolith.</p> <p class="text-align-justify">The idea behind Micro Frontends is to think about a website or web app as a composition of features that are owned by independent teams. Each team has a distinct area of business or mission it cares about and specializes in. A team is cross-functional and develops its features end-to-end, from the database to user interface.</p> <p class="text-align-justify">However, this idea is not new. It has a lot in common with the Self-contained Systems concept. In the past approaches like this went by the name of Frontend Integration for Verticalized Systems. But Micro Frontends is clearly a more friendly and less bulky term.</p> <h4 class="text-align-justify"><br /> Monolithic Frontends</h4> <h4 class="text-align-justify"><img alt="Micro-frontend-1" class="img-responsive" data-entity-type="file" data-entity-uuid="c2d267e7-4671-48c3-ab68-048f47a97149" src="/sites/default/files/inline-images/1.png" width="1278" height="499" loading="lazy" /></h4> <h4 class="text-align-justify"> </h4> <h4 class="text-align-justify"><br /> Organization in Verticals</h4> <h3 class="text-align-justify"><img alt="Micro-frontend-2" class="img-responsive" data-entity-type="file" data-entity-uuid="4eaf700c-4f70-44bd-acbd-2215e8f1890c" src="/sites/default/files/inline-images/2.png" width="1840" height="1054" loading="lazy" /></h3> <h3 class="text-align-justify"><br /> Core Ideas behind Micro Frontends</h3> <h4 class="text-align-justify">•    Be Technology Agnostic</h4> <p class="text-align-justify">Each team should be able to choose and upgrade their stack without having to coordinate with other teams. Custom Elements are a great way to hide implementation details while providing a neutral interface to others.</p> <h4 class="text-align-justify">•    Isolate Team Code</h4> <p class="text-align-justify">Don’t share a run time, even if all teams use the same framework. Build independent apps that are self-contained. Don’t rely on shared state or global variables.</p> <h4 class="text-align-justify">•    Establish Team Prefixes</h4> <p class="text-align-justify">Agree on naming conventions where isolation is not possible yet. Name space CSS, Events, Local Storage, and Cookies to avoid collisions and clarify ownership.</p> <h4 class="text-align-justify">•    Favor Native Browser Features Over Custom APIs</h4> <p class="text-align-justify">Use Browser Events for communication instead of building a global Pub Sub system. If you really have to build a cross-team API, try keeping it as simple as possible.</p> <h4 class="text-align-justify">•    Build a Resilient Site</h4> <p class="text-align-justify">Your feature should be useful, even if JavaScript failed or hasn’t executed yet. Use Universal Rendering and Progressive Enhancement to improve perceived performance.<br />  <br />       </p> <h3 class="text-align-justify">Micro-Frontend With ASP.NET And MVC</h3> <p class="text-align-justify">Many development teams have spent the last few years organizing and empowering cross-functional teams, building independently managed micro services, and implementing DevOps pipelines to go faster than ever!</p> <p class="text-align-justify">These industry shifts, critical for organizations to plan less and react more, solved old problems while creating new ones. As we focused on designing domain-aligned micro services, we also engineered JSON-hungry responsive UIs, Single Page Apps, and portals to consume them. A ton of client-side code has been thrown into our frontend layers creating monoliths, which are often maintained by a different team. Front ends have become increasingly more complex, interdependent and highly coupled to whatever Angular, React, Ember, Vue framework was cool when it was built.</p> <p class="text-align-justify"><img alt="Micro-frontend-3" class="img-responsive" data-entity-type="file" data-entity-uuid="a9fe5ab1-743a-47b9-8b3e-95979d8b34c9" src="/sites/default/files/inline-images/3.jpg" width="1028" height="597" loading="lazy" /></p> <p class="text-align-justify"> </p> <p class="text-align-justify">As a result, Micro-frontend strategies and patterns have emerged to break the monolith and promise independent, friction less, end-to-end control of feature code. A Micro-frontend design decomposes your application into smaller isomorphic functions rather than writing large interconnected front-end UIs. Here is a quick run-down of the general implementation approaches each come with their own tradeoffs.</p> <p class="text-align-justify"><strong>Composition UI</strong>: Micro services contain backend and frontend display logic, returning HTML and JS/CSS dependency references to the consumer.</p> <p class="text-align-justify"><strong>Multiple single-page apps</strong>: Fully independent micro sites living at different URLs.</p> <p class="text-align-justify"><strong>Integration at the Code Level</strong>: A more traditional approach that uses a shared code or an app shell with componentized, team owned functionalities added to pages.</p> <p class="text-align-justify"><img alt="Micro-frontend-4" class="img-responsive" data-entity-type="file" data-entity-uuid="a9488d4b-9e19-4780-b534-475c9ce85d3f" src="/sites/default/files/inline-images/4.jpg" width="1028" height="267" loading="lazy" /></p> <p class="text-align-justify"> </p> <p class="text-align-justify">Choosing the most appropriate implementation depends on your tolerance for WET (Write Every Time) autonomy versus DRY (Don't Repeat Yourself) co-dependency.</p> <p class="text-align-justify">For those already using an ASP.NET Core MVC frontend, we can leverage framework features to support code-level integrated micro-frontends.</p> <p class="text-align-justify"><img alt="Micro-frontend-5" class="img-responsive" data-entity-type="file" data-entity-uuid="90cdca21-a57a-4f0b-8214-22e2353f8fc2" src="/sites/default/files/inline-images/5.jpg" width="1028" height="379" loading="lazy" /></p> <p class="text-align-justify"> </p> <h4 class="text-align-justify">View Components</h4> <p class="text-align-justify">If you need a way to bundle up bits of UI and related behind-the-scenes logic, chances are you're looking for View Components in ASP.NET Core MVC.</p> <p class="text-align-justify">View Components don't use model binding and depend only on the data you provide, making it an ideal choice for rendering logic like shopping carts, content lists, or any componentized feature. View Components support parameters and have a backing class making them suitable for complex functionalities. They share the same separation-of-concerns and testability benefits found between view and controllers. Additionally, View Components can be externalized, loaded from a class library, packaged via NuGet, and shared across multiple applications making them an excellent ownership boundary for feature teams.</p> <p class="text-align-justify"> </p> <p class="text-align-justify"><img alt="Micro-frontend-6" class="img-responsive" data-entity-type="file" data-entity-uuid="3176b28e-b873-4a22-8bdf-d536fa5d89b3" src="/sites/default/files/inline-images/6.jpg" width="1028" height="578" loading="lazy" /></p> <p class="text-align-justify"><br /> These characteristics allow feature teams to independently manage microservices and their frontends by deploying parameterized View Components for consuming applications.</p> <p class="text-align-justify">Invoking View Components is easy within an MVC view. Tag Helpers provide an HTML-friendly experience with Intellisense support.</p> <h4 class="text-align-justify"><br /><strong>FrontendView.cshtml</strong></h4> <pre> &lt;!--other shared code--&gt; &lt;div class="row"&gt; &lt;div class="col-md-12"&gt; @await Component.InvokeAsync("GoldTeam.BannerAds") &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="col-md-4"&gt; &lt;!--tag helper--&gt; &lt;green-team-related-items itemCount="4"&gt;&lt;/green-team-related-items&gt; &lt;/div&gt; &lt;div class="col-md-8"&gt; @await Component.InvokeAsync("BlueTeam.ProductDetail",new {displayType = "simple"}) &lt;/div&gt; &lt;/div&gt; &lt;!--other shared code--&gt; </pre> <h3><br /> Summary</h3> <p class="text-align-justify">Micro service architectures have created new challenges in unexpected places. ASP.NET Core MVC View Components provide a mechanism for teams to isolate and manage frontend feature code, clearly define ownership and enhance agility. Regardless of your implementation strategy, breaking down Frontend monoliths into independently testable and deployable features will continue to be an emerging trend.<br />  </p> </div> <div class="field field--name-field-media-single field--type-entity-reference field--label-above"> <div class="field--label">Banner image</div> <div class="field--item"><a href="/en/media/394" hreflang="en">Micro_Frontend_Feature.png</a></div> </div> <section> <h2>Comments</h2> <div class="row bs-1col comment comment--type-comment comment--view-mode-default"> <div class="col-sm-12 bs-region bs-region--main"> <div class="form-item js-form-item form-wrapper js-form-wrapper panel panel-default" id="bootstrap-panel"> <div class="panel-body"> <div class="field field--name-field-your-name field--type-string field--label-hidden field--item">Debora</div> <div class="field field--name-comment-post-date field--type-ds field--label-hidden field--item">28 January 2021</div> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Heya i am for the primary time here. I found this board and I<br /> in finding It truly useful &amp; it helped me oout much.</p> <p>I'm hoping to provide something back and aid others like you<br /> aided me.<br /> <a href="https://yardleyua58dc1.medium.com/jane-schaffer-essay-example-177765970595">https://yardleyua58dc1.medium.com/jane-schaffer-essay-example-177765970…</a><br /> Listed here you’ll obtain the topp notch British isles essays done according to your<br /> guidelines.<br /> custom dissertation writers<br /> custom dissertation writers</p> </div> </div> </div> </div> </div> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=117&amp;2=field_comments&amp;3=comment" token="_P2gzHTC1y0enRlOGkmUzFYWex3CkfFMKSp5RHIzU70"></drupal-render-placeholder> </section> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/en/taxonomy/term/47" hreflang="en">Micro-frontends</a></div> <div class="field--item"><a href="/en/taxonomy/term/48" hreflang="en">Micro</a></div> <div class="field--item"><a href="/en/taxonomy/term/49" hreflang="en">frontends</a></div> <div class="field--item"><a href="/en/taxonomy/term/50" hreflang="en">MVC</a></div> <div class="field--item"><a href="/en/taxonomy/term/51" hreflang="en">.net</a></div> <div class="field--item"><a href="/en/taxonomy/term/52" hreflang="en">Core</a></div> </div> </div> <div class="field field--name-field-author field--type-entity-reference field--label-above"> <div class="field--label">Author</div> <div class="field--item"><a href="/en/node/116" hreflang="en">Saleh Alblwi</a></div> </div> Wed, 20 Jan 2021 10:13:54 +0000 zrik 117 at https://old.t2.sa