<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Satish Yadav</title>
    <description>The latest articles on DEV Community by Satish Yadav (@satish).</description>
    <link>https://dev.to/satish</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F582034%2F172ab2cf-a7d4-44c2-a353-100699287901.jpeg</url>
      <title>DEV Community: Satish Yadav</title>
      <link>https://dev.to/satish</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/satish"/>
    <language>en</language>
    <item>
      <title>What's new in .NET 8?</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Thu, 16 Nov 2023 19:33:03 +0000</pubDate>
      <link>https://dev.to/satish/whats-new-in-net-8-k1j</link>
      <guid>https://dev.to/satish/whats-new-in-net-8-k1j</guid>
      <description>&lt;p&gt;The release of .NET 8 heralds a new era in software development, marking a significant milestone in the evolution of the .NET ecosystem. This iteration introduces a plethora of groundbreaking technical enhancements designed to amplify the capabilities of developers and the performance of applications across various domains.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9g6lablhoffol3h80i33.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9g6lablhoffol3h80i33.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Unprecedented Performance Optimizations
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2r2dy7pqyjrx9qy5rksq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2r2dy7pqyjrx9qy5rksq.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The latest iteration of .NET brings forth several performance optimizations that significantly augment application efficiency and responsiveness:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Profile-Guided Optimization (PGO):&lt;/strong&gt; Enabling up to a 20% improvement in application performance through real-world usage-based code optimization.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AVX-512 Support:&lt;/strong&gt; Empowering parallel operations on 512-bit data vectors, ensuring enhanced data processing capabilities and accelerated computational throughput.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;UTF-8 Formattable and Parsable Interface:&lt;/strong&gt; Direct UTF-8 formatting and parsing capabilities sans transcoding overhead, fortifying application efficiency and responsiveness.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  .NET Aspire: Redefining Cloud-Native Development
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hw14vpg0ndxhobsz4z6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hw14vpg0ndxhobsz4z6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;.NET Aspire represents a curated collection of components tailored explicitly for cloud-native application development. With an emphasis on resilience, observability, and simplified configuration, it provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Curated Components:&lt;/strong&gt; Equipped with enhanced telemetry, resilience, configuration, and health check capabilities by default.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Streamlined Local Developer Experience:&lt;/strong&gt; Simplified acquisition and configuration of essential dependencies for cloud-native applications, facilitating a seamless development journey.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Augmented Container Capabilities in .NET 8
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3pb2t8g3rbyf9pr5p5rh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3pb2t8g3rbyf9pr5p5rh.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Containerized application deployment is further fortified in .NET 8, ensuring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Container Security:&lt;/strong&gt; Incorporation of non-root users within .NET images, bolstering container security measures.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Compact Image Sizes:&lt;/strong&gt; Faster deployment facilitated by minimized .NET base image sizes, optimizing resource utilization.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Native AoT - Facilitating Compute Efficiency
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F35hqjnjc7joi8o3zwuca.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F35hqjnjc7joi8o3zwuca.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Compile .NET applications into native code to minimize memory footprint and expedite app initialization:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Compiled Native Code:&lt;/strong&gt; Immediate app startup without JIT compilation overhead, facilitating operation in restricted environments.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Integrating Artificial Intelligence with .NET
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7rqk572mz1g2j26y1e1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7rqk572mz1g2j26y1e1.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Harness the power of generative AI and large language models, seamlessly integrated into .NET 8:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Generative AI Integration:&lt;/strong&gt; Simplified AI integration with first-class out-of-the-box AI features within the .NET SDK.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;System.Numerics Library Enhancements:&lt;/strong&gt; Enhanced compatibility with Generative AI workloads, integrating Tensor Primitives.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Advanced Web Application Development with Blazor
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsxodpjtkp4ln4g20t00r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsxodpjtkp4ln4g20t00r.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blazor in .NET 8 introduces innovative features for comprehensive web UI development:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blazor Server and Blazor WebAssembly Integration:&lt;/strong&gt; Full-stack web UI capabilities merging server and client-side functionalities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Robust Authentication and Authorization:&lt;/strong&gt; Full support for Blazor-based Identity UI, elevating security measures.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  .NET MAUI - Unifying Cross-Platform Development
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsz3sr0deqokhzoylu2s3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsz3sr0deqokhzoylu2s3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;.NET MAUI revolutionizes cross-platform app development, unifying project systems across multiple platforms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unified Project System:&lt;/strong&gt; Develop WinUI, Mac Catalyst, iOS, and Android applications from a single codebase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Quality Improvements:&lt;/strong&gt; Enhanced performance, controls, UI elements, and platform-specific behaviors.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  C# 12 Features - Amplifying Developer Productivity
&lt;/h2&gt;

&lt;p&gt;The introduction of C# 12 brings forth a range of productivity enhancements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Primary Constructors:&lt;/strong&gt; Streamlined class initialization, minimizing boilerplate code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Concise Collection Types:&lt;/strong&gt; Simplified array and span creation, augmenting code readability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lambda Expression Parameter Defaults:&lt;/strong&gt; Improved handling of optional arguments within lambda expressions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Broader .NET 8 Support Across Development Tools
&lt;/h2&gt;

&lt;p&gt;Visual Studio 2022 17.8 and Visual Studio Code's C# Dev Kit offer extended support for .NET 8, empowering developers with advanced tooling capabilities across diverse development environments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional new features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://ASP.NET" rel="noopener noreferrer"&gt;&lt;strong&gt;ASP.NET&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;Core&lt;/strong&gt;: Streamlines identity for single-page applications (SPA) and Blazor providing cookie-based authentication, pre-built APIs, token support, and a new identity UI. Enhances minimal APIs with form-binding, antiforgery support to protect against cross-site request forgery (XSRF/CSRF), and asParameters support for parameter-binding with Open API definitions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://ASP.NET" rel="noopener noreferrer"&gt;&lt;strong&gt;ASP.NET&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;Core Tooling&lt;/strong&gt;: Route syntax highlighting, auto-completion, and analyzers to help you create Web APIs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;: Provides new “complex types” as value objects, primitive collections, and SQL Server support for hierarchical data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;NuGet&lt;/strong&gt;: Helps you audit your NuGet packages in projects and solutions for any known security vulnerabilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.NET Runtime&lt;/strong&gt;: Brings a new AOT compilation mode for WebAssembly (WASM) and Android.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.NET SDK&lt;/strong&gt;: Revitalizes terminal build output and production-ready defaults.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;WPF&lt;/strong&gt;: Supports OpenFolderDialog and Enabled HW Acceleration in RDP.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ARM64&lt;/strong&gt;: Significant feature enhancements and improved code quality for ARM64 platforms through collaboration with ARM engineers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debugging&lt;/strong&gt;: Displays debug summaries and provides simplified debug proxies for commonly used .NET types.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;System.Text.Json&lt;/strong&gt;: Helps populate read-only members, customizes unmapped member handling, and improves Native AOT support.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.NET Community Toolkit&lt;/strong&gt;: Accelerates building .NET libraries and applications while ensuring they are trim and AOT compatible (including the MVVM source generators!)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Azure&lt;/strong&gt;: Supports .NET 8 with Azure’s PaaS services like App Service for Windows and Linux, Static Web Apps, Azure Functions, and Azure Container Apps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;F# 8&lt;/strong&gt;: Includes significant language changes, new diagnostics, improvements in usability, and performance enhancements in project compilation, as well as upgrades to the FSharp.Core standard library.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;.NET 8 stands as a testament to continuous innovation, fostering a robust ecosystem for developers to craft high-performance, resilient, and scalable applications across diverse domains. It represents a leap forward in the realm of software development, revolutionizing the way applications are built and optimized.&lt;/p&gt;

&lt;p&gt;Embrace the future of development with .NET 8, explore its technical depths, and join my journey at my blog here at &lt;a href="https://blog.satishyadav.com" rel="noopener noreferrer"&gt;https://blog.satishyadav.com&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dotnet.microsoft.com/download/dotnet/8.0" rel="noopener noreferrer"&gt;Download .NET 8&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dotnet.microsoft.com/platform/upgrade-assistant" rel="noopener noreferrer"&gt;Upgrade your old apps to .NET 8&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dotnet</category>
      <category>dotnet8</category>
      <category>csharp</category>
    </item>
    <item>
      <title>5 things I wish I knew before writing 1 Million lines of code</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Mon, 26 Jun 2023 12:25:36 +0000</pubDate>
      <link>https://dev.to/satish/5-things-i-wish-i-knew-before-writing-1-million-lines-of-code-1b9h</link>
      <guid>https://dev.to/satish/5-things-i-wish-i-knew-before-writing-1-million-lines-of-code-1b9h</guid>
      <description>&lt;p&gt;Developers spend much more time reading the code than writing it. So, after optimizing code for time and space complexity — optimize it for reading complexity. There’s even a term for that — Cyclomatic Complexity.&lt;/p&gt;

&lt;p&gt;After having written more than 1 million lines of code and having read much more awful lot, here are the top 5 things I wish I knew sooner to write more readable code.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Your code will be read more times than you think.
&lt;/h2&gt;

&lt;p&gt;A common misconception among upcoming and new developers is — Software Development is about writing the O(n) complexity code of binary tree inversion. And I hate to break it to you — it’s not.&lt;/p&gt;

&lt;p&gt;A lot of time it’s about, adding a new feature or fixing a bug in an existing code base with its own coding conventions, naming conventions, design, and architecture. So reading and understanding the existing code becomes one of the most important parts of the job.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Great developers spend a lot of time reading other people’s code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  2. Readable code &amp;gt; Smart Code
&lt;/h2&gt;

&lt;p&gt;In almost all programming languages and frameworks, there are numerous ways of doing the same thing. The smarter and one-liner way may feel good to write at the moment, but often it’s not good for the next reader — which can be YOU six months down the line.&lt;/p&gt;

&lt;p&gt;So,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If there is a little more verbose but more readable way to do it — do it and your future self will thank you later.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  3. Document the “why” instead of “what”.
&lt;/h2&gt;

&lt;p&gt;Usually, I’m against documentation. Because&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The code is literally the instructions written to build something.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The only parts that need documentation are the “why”. Why we’ve written this piece of code this way?&lt;/p&gt;

&lt;p&gt;If you don't understand the "what"? Maybe you shouldn't be the one changing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Describe everything your function/method does in the name.
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;There are only 2 difficult things in Computer Science — Cache Invalidation and Naming&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just by reading the name of the function, its intent should be clear.&lt;/p&gt;

&lt;p&gt;“But then large functions would have way big names” — that’s the point. Your function should do only 1 or a few things and do it properly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Refactor the function/method if it’s job can’t be described in the name.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  5. “Deadline” is a silly excuse for writing bad code.
&lt;/h2&gt;

&lt;p&gt;“There’s no time to write good code” is not a good enough excuse for writing bad code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Checking for the readability of your code is like flushing the toilet — it’s part of the ceremony. You do it no matter how late you are for anything else.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So next time you write code, think about your future self, what would you answer to that person? Don’t bring the shame to yourself. Write readable code.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>coding</category>
      <category>softwareengineering</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Managing Technical Debt with NDepend!</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Sat, 03 Sep 2022 09:21:42 +0000</pubDate>
      <link>https://dev.to/satish/managing-technical-debt-with-ndepend-4240</link>
      <guid>https://dev.to/satish/managing-technical-debt-with-ndepend-4240</guid>
      <description>&lt;h2&gt;
  
  
  What the hell is a Technical Debt?
&lt;/h2&gt;

&lt;p&gt;You are working on a cool new project, want to implement the amazing new design pattern that you learned about few days ago. All is well. Until, your boss comes to your desk and tells you the release is pre-poned (is that even a word?) by 10 days. WTH man! Now whatever plans you had to make the code readable, testable, SOLID - goes for a toss, and you stuff the code to make up for the early release.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So you bought some time by writing "not so good code" to meet the deadline.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let this sink in for a moment.&lt;/p&gt;

&lt;p&gt;You know that the code that you had written needs to be refactored, but you don't have the bandwidth (not the internet one) to do so, so you live with this "bad code" - aka &lt;code&gt;technical debt&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Well, debts inherently aren't bad, you take debts all the time - Credit Cards, Car Loan, House Loan. But you need to pay the interest, and as long you re-pay, it's well and good. Same goes for the technical debt. It's a trade-off between Product Delivery and impeccable code.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I know that I have a Technical Debt
&lt;/h2&gt;

&lt;p&gt;Some times ago, I did not have any single tool which can give a clear idea what kind of and how much technical debt I have. &lt;/p&gt;

&lt;p&gt;I was looking at different metrics e.g., Code Duplication, Cyclomatic Complexity, Test Coverage, Dependency and Coupling, and more to get an idea.&lt;/p&gt;

&lt;p&gt;Then I stumbled upon &lt;a href="https://www.ndepend.com/?utm_source=blog.satishyadav.com&amp;amp;utm_medium=technical_debt_blog_post"&gt;&lt;code&gt;NDepend&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;NDepende can scan your code-base and tell you how much technical debt you have in a single actionable dashboard?&lt;/p&gt;

&lt;h2&gt;
  
  
  What is NDepend
&lt;/h2&gt;

&lt;p&gt;NDepend can do much more than that, e.g.,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code Rule and Code Query over LINQ (CQLinq)&lt;/li&gt;
&lt;li&gt;Powerful Dependency Graph and Matrix&lt;/li&gt;
&lt;li&gt;Smart Technical Debt Estimation&lt;/li&gt;
&lt;li&gt;Quality Gates&lt;/li&gt;
&lt;li&gt;In-Depth Issues Management&lt;/li&gt;
&lt;li&gt;Trend Monitoring&lt;/li&gt;
&lt;li&gt;Harness Test Coverage Data&lt;/li&gt;
&lt;li&gt;Code Quality and Code Metrics&lt;/li&gt;
&lt;li&gt;Detect Dependency Cycles&lt;/li&gt;
&lt;li&gt;Code Diff since Baseline&lt;/li&gt;
&lt;li&gt;Enforce Immutability and Purity&lt;/li&gt;
&lt;li&gt;Complexity and Diagrams&lt;/li&gt;
&lt;li&gt;Continuous Integration Reporting&lt;/li&gt;
&lt;li&gt;Warnings on Build&lt;/li&gt;
&lt;li&gt;Process Health&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and more. &lt;/p&gt;

&lt;p&gt;They consider themselves, &lt;em&gt;The "Swiss Army Knife" for .NET Developers, Architects and Teams&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Visit their &lt;a href="https://www.ndepend.com/?utm_source=blog.satishyadav.com&amp;amp;utm_medium=technical_debt_blog_post"&gt;official site&lt;/a&gt; to know more.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NDepende team was generous to give me a copy of their license to try out the product&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you're new to NDepend or want to know how to install and get started, folks at NDepend have written a wonderful step-by-step documentation.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Thing I like about NDepend is, it gives me a visual dashboard which is actionable. And all the data it provides, it has LINQ queries to support that and accommodate custom rules as well.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How to find out Technical Debt
&lt;/h2&gt;

&lt;p&gt;For this post, I've taken the &lt;a href="https://github.com/jasontaylordev/CleanArchitecture?utm_source=blog.satishyadav.com&amp;amp;utm_medium=technical_debt_blog_post"&gt;Clean Architecture repo&lt;/a&gt; from &lt;a href="https://github.com/jasontaylordev?utm_source=blog.satishyadav.com&amp;amp;utm_medium=technical_debt_blog_post"&gt;Jason Taylor&lt;/a&gt;. If you don't know Jason, he's the Clean Architecture guy, a great developer, trainer, architect, and more.&lt;/p&gt;

&lt;p&gt;Once you clone the repo in Visual Studio, here's how the Project structure looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rdW4pxWB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/project-structure.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rdW4pxWB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/project-structure.png" alt="project-structure" width="368" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An Angular SPA with Application Layer, Domain Layer, Infrastructure Layer - basically the Clean Architecture.&lt;/p&gt;

&lt;p&gt;Attached the NDepend to this solution:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n2Rbxz_h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/attach-to-solution.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n2Rbxz_h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/attach-to-solution.png" alt="attach-to-solution" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NDepend will detect the projects and exclude test projects. Click on Analyze X NET Assemblies.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2gd5lz-n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/pre-run.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2gd5lz-n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/pre-run.png" alt="pre-run" width="800" height="562"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Give it some time to finish.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e9dv2sG6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/finshed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e9dv2sG6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/finshed.png" alt="finished" width="764" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the View NDepend Dashboard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dashboard
&lt;/h2&gt;

&lt;p&gt;The dashboard gives you plethora of information about the Project code quality, lines of code, issues, comments, but we're interested in technical debt.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s0c7XTML--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/project-dashboard.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s0c7XTML--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/project-dashboard.png" alt="dashboard" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case, you can see there is a 5.56% of technical debt. Well done, Jason!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Smart Technical Debt feature of NDepend also tell us how many days it would take us to resolve the technical debt.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Amazing, right?&lt;/p&gt;

&lt;p&gt;Additionally, it gives us the Rating of the project based on Technical Debt. In our case &lt;em&gt;B&lt;/em&gt;. Pretty good. And how much effort is required to reach to &lt;em&gt;A&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exploring Technical Debt
&lt;/h2&gt;

&lt;p&gt;If you click on the rating, NDepend will show you the hot-spots of the code where most of the debt is.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6L2rdA7g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/hotspot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6L2rdA7g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/hotspot.png" alt="hotspot" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clicking on the Debt % gives list of all the issue&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YWZY8V6n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/rules.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YWZY8V6n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/rules.png" alt="rules" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on a specific rule to find out the details  and what all code has contributed to this technical debt.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5hx4dFIk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/rule-detail.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5hx4dFIk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.satishyadav.com/images/rule-detail.png" alt="rule-detail" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, our code base has violated following rule:&lt;/p&gt;

&lt;p&gt;• Rule Name: Avoid namespaces dependency cycles&lt;br&gt;
 • Rule Id: ND1401&lt;br&gt;
 • Rule Explicit Id: AvoidNamespacesDependencyCycles&lt;/p&gt;

&lt;p&gt;• Rule Description:  &lt;/p&gt;

&lt;p&gt;This rule lists all application namespace dependency cycles. Each row shows a different cycle, indexed with one of the namespace entangled in the cycle. &lt;/p&gt;

&lt;p&gt;Read our white books relative to partitioning code, to know more about namespaces dependency cycles, and why avoiding them is a simple yet efficient solution to clean the architecture of a code base. &lt;a href="https://www.ndepend.com/docs/white-books?utm_source=blog.satishyadav.com&amp;amp;utm_medium=technical_debt_blog_post"&gt;https://www.ndepend.com/docs/white-books&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;• How to Fix Issues of this Rule:  &lt;/p&gt;

&lt;p&gt;Removing first pairs of mutually dependent namespaces will eliminate most namespaces dependency cycles. This is why it is recommended to focus first on matches of the default rule Avoid namespaces mutually dependent before attempting to fix issues of the present rule. &lt;/p&gt;

&lt;p&gt;Once all mutually dependent namespaces occurrences are solved, remaining cycles matched by the present rule necessarily involve 3 or more namespaces like in: A is using B is using C is using A. &lt;/p&gt;

&lt;p&gt;To browse a cycle on the dependency graph or the dependency matrix, right click a cycle cell in the result of the present rule and export the matched namespaces to the dependency graph or matrix. This is illustrated here: &lt;a href="https://www.ndepend.com/docs/visual-studio-dependency-graph#Entangled?utm_source=blog.satishyadav.com&amp;amp;utm_medium=technical_debt_blog_post"&gt;https://www.ndepend.com/docs/visual-studio-dependency-graph#Entangled&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With such a cycle graph visualized, you can determine which dependencies should be discarded to break the cycle. To do so, you need to identify which namespace should be at low-level and which one should be at high-level. &lt;/p&gt;

&lt;p&gt;In the A is using B is using C is using A cycle example, if A should be at low level then C should be at a higher-level than A. As a consequence C shouldn't use A and this dependency should be removed. To remove a dependency you can refer to patterns described in the HowToFix section of the rule Avoid namespaces mutually dependent. &lt;/p&gt;

&lt;p&gt;Notice that the dependency matrix can also help visualizing and breaking cycles. In the matrix cycles are represented with red squares and black cells. To easily browse dependency cycles, the dependency matrix comes with an option: Display Direct and Indirect Dependencies. See related documentation here: &lt;a href="https://www.ndepend.com/docs/dependency-structure-matrix-dsm#Cycle%20https://www.ndepend.com/docs/dependency-structure-matrix-dsm#Mutual?utm_source=blog.satishyadav.com&amp;amp;utm_medium=technical_debt_blog_post"&gt;https://www.ndepend.com/docs/dependency-structure-matrix-dsm#Cycle https://www.ndepend.com/docs/dependency-structure-matrix-dsm#Mutual&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The estimated Debt, which means the effort to fix such issue, doesn't depend on the cycle length. First because fixing the rule Avoid namespaces mutually dependent will fix most cycle reported here, second because even a long cycle can be broken by removing a single or a few dependencies.&lt;/p&gt;

&lt;p&gt;• How to Suppress an Issue of this Rule:  &lt;/p&gt;

&lt;p&gt;In source code, tag the concerned code element with this attribute:&lt;br&gt;
[SuppressMessage("NDepend", "ND1401:AvoidNamespacesDependencyCycles", Justification="...")]&lt;br&gt;
This attribute requires the compilation symbol CODE_ANALYSIS to be set on each Visual Studio project relying on it. Without CODE_ANALYSIS symbol defined, the attribute is not compiled and the issues are not suppressed.&lt;/p&gt;

&lt;p&gt;Pretty detailed, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  Next steps
&lt;/h2&gt;

&lt;p&gt;Now you have a basic understanding of what Technical Debt is and how NDepend can take you into your journey of becoming Technical-Debt-free (if that's a thing).&lt;/p&gt;

&lt;p&gt;Visit the NDepend site to learn more.&lt;/p&gt;

&lt;p&gt;Here's the repo used in this post, give this a star:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/iSatishYadav/CleanArchitectureCodeBase"&gt;https://github.com/iSatishYadav/CleanArchitectureCodeBase&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Originally posted at:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.satishyadav.com/managing-technical-debt-with-ndepend"&gt;https://blog.satishyadav.com/managing-technical-debt-with-ndepend&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>technicaldebt</category>
      <category>dotnet</category>
      <category>ndepend</category>
    </item>
    <item>
      <title>Automate Windows Software and Apps' installation!</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Sun, 28 Aug 2022 13:13:11 +0000</pubDate>
      <link>https://dev.to/satish/automate-windows-software-and-apps-installation-37p3</link>
      <guid>https://dev.to/satish/automate-windows-software-and-apps-installation-37p3</guid>
      <description>&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;If you've installed Windows enough times, you already know the pain of installing all your Software and Apps again and again. If you haven't, let me save you the pain and show you how to:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Automate the installation of Windows Software and Apps&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Package Manager FTW!
&lt;/h2&gt;

&lt;p&gt;What we need here is something called Package Manager, which we can give some commands and it would install the software from the command line itself.&lt;/p&gt;

&lt;p&gt;Why command line — so that we can repeat the process.&lt;/p&gt;

&lt;p&gt;&lt;del&gt;Windows doesn't have an official Package Manager yet&lt;/del&gt;, but &lt;a href="https://chocolatey.org/"&gt;Chocolatey&lt;/a&gt; is your safest bet.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Windows has gotten &lt;code&gt;winget&lt;/code&gt; but it's relatively new and community support/references are much better for Chocolatey. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So here's what we're going to do, we need to search and list down all the software that we typically install and save that command at a place where we can refer it later. It can be on any of Drives (Google Drive, OneDrive) or if you're a developer or power user (whatever that is) - on a Git repo. I don't care, as long as you have the access to it when the time comes.&lt;/p&gt;

&lt;p&gt;So let's get to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Install Chocolatey itself
&lt;/h2&gt;

&lt;p&gt;From an Admin terminal (PowerShell or Windows Terminal)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Set-ExecutionPolicy Bypass &lt;span class="nt"&gt;-Scope&lt;/span&gt; Process &lt;span class="nt"&gt;-Force&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; iex &lt;span class="o"&gt;((&lt;/span&gt;New-Object System.Net.WebClient&lt;span class="o"&gt;)&lt;/span&gt;.DownloadString&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://community.chocolatey.org/install.ps1'&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
&lt;span class="sb"&gt;```&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;


&lt;span class="c"&gt;## 2. Install packages&lt;/span&gt;
If you know alrady familiar with the package names of individual Software or the App, you can skip this otherwise you can search 

&lt;span class="c"&gt;### 2.1 Search&lt;/span&gt;
Let&lt;span class="s1"&gt;'s say I don'&lt;/span&gt;t know what is the name of the Node.js package. I can serach:

&lt;span class="c"&gt;#### 2.1.1 Search from CLI&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;


&lt;span class="sb"&gt;````&lt;/span&gt;shell
choco search nodejs
&lt;span class="sb"&gt;```&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;

It should &lt;span class="k"&gt;return &lt;/span&gt;results something like that:
&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;


&lt;span class="sb"&gt;````&lt;/span&gt;shell
nodejs 16.11.0 &lt;span class="o"&gt;[&lt;/span&gt;Approved]
nodejs.commandline 6.11.0 &lt;span class="o"&gt;[&lt;/span&gt;Approved]
nodejs.install 16.11.0 &lt;span class="o"&gt;[&lt;/span&gt;Approved]
nodejs-lts 14.18.0 &lt;span class="o"&gt;[&lt;/span&gt;Approved]
...
30 packages found.

&lt;span class="sb"&gt;```&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;


&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Homework: What does &lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;Approved]&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt; mean?

&lt;span class="c"&gt;#### 2.1.1 Seach from Chocolatey site:&lt;/span&gt;

Visit https://community.chocolatey.org/packages to find all the supported packages. You can find all sorts of amazing Software and Apps including day-to-day Sofrware like Chrome, Zoom, iTunes - to Enterprise Developer Tools like Visual Studio, Python, Azure and AWS CLIs - and whatnot.

&lt;span class="c"&gt;### 2.2 Install &lt;/span&gt;

This is how you &lt;span class="nb"&gt;install &lt;/span&gt;a pacakge. From an Admin terminal:

&lt;span class="k"&gt;*&lt;/span&gt; Node.js
&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="sb"&gt;````&lt;/span&gt;shell
choco &lt;span class="nb"&gt;install &lt;/span&gt;nodejs-lts
&lt;span class="sb"&gt;```&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;*&lt;/span&gt; VS Code
&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="sb"&gt;````&lt;/span&gt;shell
choco &lt;span class="nb"&gt;install &lt;/span&gt;vscode
&lt;span class="sb"&gt;```&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;


Now you can save all this &lt;span class="k"&gt;in &lt;/span&gt;a file and &lt;span class="nb"&gt;install&lt;/span&gt;, but &lt;span class="nb"&gt;wait&lt;/span&gt; &lt;span class="s2"&gt;"where is the automation you promised? I need my money back."&lt;/span&gt; Don&lt;span class="s1"&gt;'t worry, people way smarter than me have thought about this and came up with:

## Packages.config
There'&lt;/span&gt;s an official way to list all the packages and &lt;span class="nb"&gt;install &lt;/span&gt;from that file.

Here&lt;span class="s1"&gt;'s what a typical package looks like:
{% raw %}


````xml
&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;packages&amp;gt;
    &amp;lt;package id="vscode" /&amp;gt;
    &amp;lt;package id="nodejs-lts" version="14.18.0" /&amp;gt;
&amp;lt;/packages&amp;gt;
```



Save this file and in future you can install all the Software and Apps. e.g.



````shell
choco install "sample-packages.config"
```



Since I already have these pacakges installed, I got following message, but you can figure it out from here.



````shell
Installing from config file:
sample-packages.config
By installing, you accept licenses for the packages.
Installing the following packages:
vscode
nodejs-lts
vscode v1.61.0 already installed.
 Use --force to reinstall, specify a version to install, or try upgrade.
nodejs-lts v14.18.0 already installed.
 Use --force to reinstall, specify a version to install, or try upgrade.

Chocolatey installed 0/2 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
```


## Conclusion

That'&lt;/span&gt;s it! This is how you can automate the installation of your favorite Software and Apps &lt;span class="k"&gt;in &lt;/span&gt;a repeatable way.

If you liked this, please like and share this post. And visit https://github.com/iSatishYadav/AutomateWindowsSoftwareInstallation and give this repo a star.

Originally posted at:

&lt;span class="o"&gt;[&lt;/span&gt;https://blog.satishyadav.com/automate-new-windows-machine-installation]&lt;span class="o"&gt;(&lt;/span&gt;https://blog.satishyadav.com/automate-new-windows-machine-installation/?utm_source&lt;span class="o"&gt;=&lt;/span&gt;devto_&amp;amp;utm_medium&lt;span class="o"&gt;=&lt;/span&gt;blog&lt;span class="o"&gt;)&lt;/span&gt;

Happy Hacking! 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>chocolatey</category>
      <category>windows</category>
      <category>automation</category>
    </item>
    <item>
      <title>An “I don’t know what Docker is and at this point I’m too afraid to ask” guide to Docker.</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Sat, 12 Mar 2022 03:41:27 +0000</pubDate>
      <link>https://dev.to/satish/hello-docker-an-i-dont-know-and-at-this-point-im-too-afraid-to-ask-guide-to-docker-3o3h</link>
      <guid>https://dev.to/satish/hello-docker-an-i-dont-know-and-at-this-point-im-too-afraid-to-ask-guide-to-docker-3o3h</guid>
      <description>&lt;h2&gt;
  
  
  What is Docker?
&lt;/h2&gt;

&lt;p&gt;Docker is an open source platform for building, deploying, and managing containerized applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. &lt;/p&gt;

&lt;p&gt;It is based on the idea that you can package your code with dependencies into a deployable unit called a "container" that has everything the software needs to run including libraries, system tools, code, and runtime. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--deqelEZs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/iSatishYadav/iSatishYadav.github.io/master/images/docker%2520logo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--deqelEZs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/iSatishYadav/iSatishYadav.github.io/master/images/docker%2520logo.png" alt="Docker logo" width="601" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wait, but what's a "Container"?
&lt;/h2&gt;

&lt;p&gt;A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. &lt;/p&gt;

&lt;p&gt;Containers are made possible by process isolation and virtualization capabilities built into the Linux kernel. As a result, container technology offers all the functionality and benefits of VMs - including application isolation, cost-effective scalability, and disposability - plus important additional advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lighter weight&lt;/li&gt;
&lt;li&gt;Greater resource efficiency&lt;/li&gt;
&lt;li&gt;Improved developer productivity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zftF-BIg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/iSatishYadav/iSatishYadav.github.io/master/images/docker.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zftF-BIg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/iSatishYadav/iSatishYadav.github.io/master/images/docker.jpeg" alt="Docker" width="345" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  That's too much of jargons, can you give me a simple analogy?
&lt;/h2&gt;

&lt;p&gt;Perhaps a simple analogy can help getting the grasp of the core concept of Docker...&lt;/p&gt;

&lt;p&gt;Let's go back in time to the 1950s for a moment. There were no word processors, and the photocopiers were used everywhere (kind of).&lt;/p&gt;

&lt;p&gt;Imagine you're responsible for quickly issuing batches of letters as required, to mail them to customers, using real paper and envelopes, to be delivered physically to each customer's address (there was no email back then).&lt;/p&gt;

&lt;p&gt;At some point, you realize the letters are just a composition of a large set of paragraphs, which are picked and arranged as needed, according to the purpose of the letter, so you devise a system to issue letters quickly, expecting to get a hefty raise.&lt;/p&gt;

&lt;p&gt;The system is simple:&lt;/p&gt;

&lt;p&gt;You begin with a deck of transparent sheets containing one paragraph each.&lt;/p&gt;

&lt;p&gt;To issue a set of letters, you pick the sheets with the paragraphs you need, then you stack and align them so they look and read fine.&lt;/p&gt;

&lt;p&gt;Finally, you place the set in the photocopier and press start to produce as many letters as required.&lt;/p&gt;

&lt;p&gt;So, simplifying, that's the core idea of Docker.&lt;/p&gt;

&lt;p&gt;In Docker, each layer is the resulting set of changes that happen to the filesystem after executing a command, such as, installing a program.&lt;/p&gt;

&lt;p&gt;So, when you "look" at the filesystem after the layer has been copied, you see all the files, included the layer when the program was installed.&lt;/p&gt;

&lt;p&gt;You can think of an image as an auxiliary read-only hard disk ready to be installed in a "computer" where the operating system is already installed.&lt;/p&gt;

&lt;p&gt;Similarly, you can think of a container as the "computer" with the image hard disk installed. The container, just like a computer, can be powered on or off.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Docker
&lt;/h2&gt;

&lt;p&gt;Using Docker lets you ship software faster, standardize application operations, seamlessly move code, and save money by improving resource utilization.&lt;/p&gt;

&lt;p&gt;With Docker, you get a single object that can reliably run anywhere. Docker's simple and straightforward syntax gives you full control. Wide adoption means there's a robust ecosystem of tools and off-the-shelf applications that are ready to use with Docker.&lt;/p&gt;

&lt;p&gt;Docker is so popular today that &lt;code&gt;Docker&lt;/code&gt; and &lt;code&gt;containers&lt;/code&gt; are used interchangeably.&lt;/p&gt;

&lt;h2&gt;
  
  
  But we already have Virtual Machines? Why Containers?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ya1C6Uur--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/iSatishYadav/iSatishYadav.github.io/master/images/container-vm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ya1C6Uur--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/iSatishYadav/iSatishYadav.github.io/master/images/container-vm.png" alt="Container vs VM" width="800" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Containers&lt;/th&gt;
&lt;th&gt;Virtual Machines&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Containers are an abstraction at the Application layer that packages code and dependencies together.&lt;/td&gt;
&lt;td&gt;Virtual machines (VMs) are an abstraction of physical hardware turning one server into many servers.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multiple containers can run on the same machine and share the OS kernel with other containers, each running as isolated processes in user space.&lt;/td&gt;
&lt;td&gt;The hypervisor allows multiple VMs to run on a single machine.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Containers take up less space than VMs (container images are typically tens of MBs in size), can handle more applications and require fewer VMs and Operating systems.&lt;/td&gt;
&lt;td&gt;Each VM includes a full copy of an operating system, the application, necessary binaries and libraries - taking up tens of GBs.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Containers boot up quickly&lt;/td&gt;
&lt;td&gt;VMs can be slow to boot.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Docker tools and terms
&lt;/h2&gt;

&lt;p&gt;Let us familiarize ourselves with Docker terminology.&lt;/p&gt;

&lt;h3&gt;
  
  
  DockerFile
&lt;/h3&gt;

&lt;p&gt;Every Docker container starts with a simple text file containing instructions for how to build the Docker container image. DockerFile automates the process of Docker image creation. It’s essentially a list of command-line interface (CLI) instructions that Docker Engine will run in order to assemble the image.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker images
&lt;/h3&gt;

&lt;p&gt;Docker images contain executable application source code as well as all the tools, libraries, and dependencies that the application code needs to run as a container. When you run the Docker image, it becomes one instance (or multiple instances) of the container.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker containers
&lt;/h3&gt;

&lt;p&gt;Docker containers are the live, running instances of Docker images. While Docker images are read-only files, containers are live, ephemeral, executable content. Users can interact with them, and administrators can adjust their settings and conditions using docker commands.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker Hub
&lt;/h3&gt;

&lt;p&gt;Docker Hub is the public repository of Docker images.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker daemon
&lt;/h3&gt;

&lt;p&gt;Docker daemon is a service running on your operating system, such as Microsoft Windows or Apple MacOS or iOS. This service creates and manages your Docker images for you using the commands from the client, acting as the control center of your Docker implementation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker registry
&lt;/h3&gt;

&lt;p&gt;A Docker registry is a scalable open-source storage and distribution system for docker images. The registry enables you to track image versions in repositories, using tagging for identification. This is accomplished using Git, a version control tool.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YK9nrXC---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/iSatishYadav/iSatishYadav.github.io/master/images/architecture.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YK9nrXC---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/iSatishYadav/iSatishYadav.github.io/master/images/architecture.svg" alt="Images" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use Docker
&lt;/h2&gt;

&lt;p&gt;You can use Docker containers as a core building block creating modern applications and platforms. Docker makes it easy to build and run distributed microservices architecures, deploy your code with standardized continuous integration and delivery pipelines, build highly-scalable data processing systems, and create fully-managed platforms for your developers. &lt;/p&gt;

&lt;h3&gt;
  
  
  Micro-Services
&lt;/h3&gt;

&lt;p&gt;Build and scale distributed application architectures by taking advantage of standardized code deployments using Docker containers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Continuous Integration &amp;amp; Delivery
&lt;/h3&gt;

&lt;p&gt;Accelerate application delivery by standardizing environments and removing conflicts between language stacks and versions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker deployment and orchestration
&lt;/h2&gt;

&lt;p&gt;If you're running only a few containers, it's fairly simple to manage your application within Docker Engine, the industry de facto runtime. But if your deployment comprises thousands of containers and hundreds of services, it's nearly impossible to manage that workflow without the help of these purpose-built tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker Compose
&lt;/h3&gt;

&lt;p&gt;If you're building an application out of processes in multiple containers that all reside on the same host, you can use Docker Compose to manage the application's architecture. Docker Compose creates a YAML file that specifies which services are included in the application and can deploy and run containers with a single command. Using Docker Compose, you can also define persistent volumes for storage, specify base nodes, and document and configure service dependencies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Kubernetes
&lt;/h3&gt;

&lt;p&gt;To monitor and manage container lifecycles in more complex environments, you'll need to turn to a container orchestration tool. While Docker includes its own orchestration tool (called Docker Swarm), most developers choose Kubernetes instead.&lt;/p&gt;

&lt;p&gt;Kubernetes is an open-source container orchestration platform descended from a project developed for internal use at Google. &lt;/p&gt;

&lt;p&gt;Kubernetes schedules and automates tasks integral to the management of container-based architectures, including container deployment, updates, service discovery, storage provisioning, load balancing, health monitoring, and more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1b79KxLx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/iSatishYadav/iSatishYadav.github.io/master/images/kubernetes.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1b79KxLx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raw.githubusercontent.com/iSatishYadav/iSatishYadav.github.io/master/images/kubernetes.png" alt="Kubernetes" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Next steps and Credits
&lt;/h2&gt;

&lt;p&gt;Visit official Docker website to learn more. All major clouds e.g. Azure, AWS, Google Cloud have Containers offerings, visit their sites for more info.&lt;br&gt;
Credits: &lt;br&gt;
&lt;a href="https://aws.amazon.com/docker/"&gt;https://aws.amazon.com/docker/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.ibm.com/cloud/learn/docker"&gt;https://www.ibm.com/cloud/learn/docker&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.docker.com/"&gt;https://www.docker.com/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.microsoft.com/en-us/dotnet/architecture/microservices/container-docker-introduction/docker-defined"&gt;https://docs.microsoft.com/en-us/dotnet/architecture/microservices/container-docker-introduction/docker-defined&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>containers</category>
      <category>kubernetes</category>
      <category>orchestration</category>
    </item>
    <item>
      <title>🆕 SQL Server 2022 First Look - Top 5 New Features (Bonus 5 Features)</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Fri, 05 Nov 2021 06:57:20 +0000</pubDate>
      <link>https://dev.to/satish/sql-server-2022-first-look-top-5-new-features-bonus-5-features-2ad3</link>
      <guid>https://dev.to/satish/sql-server-2022-first-look-top-5-new-features-bonus-5-features-2ad3</guid>
      <description>&lt;p&gt;Microsoft &lt;a href="https://cloudblogs.microsoft.com/sqlserver/2021/11/02/announcing-sql-server-2022-preview-azure-enabled-with-continued-performance-and-security-innovation/" rel="noopener noreferrer"&gt;announced&lt;/a&gt; the first private preview of SQL Server 2022 claiming "the most Azure-enabled release of SQL Server yet, with continued innovation in performance, security, and availability".&lt;/p&gt;

&lt;p&gt;In this post we're going to have a look on top 5 most interesting features.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Ledger (Blockchain) Support
&lt;/h2&gt;

&lt;p&gt;SQL Server 2022 introduces new Ledger capabilities for creating Blockchain like immutable records to ensure data integrity. If somebody modifies the record, it would no longer be valid.&lt;/p&gt;

&lt;p&gt;It would be beneficial for scenarios such as internal and external audits.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Peer-to-peer replica conflict resolution
&lt;/h2&gt;

&lt;p&gt;In a multi-write scenario - With SQL Server 2022, last-write rule is being automated. Now, when a conflict is detected, the most recent modification time will be chosen to be persisted on all replicas. This helps keep your multi-write scenarios running smoothly.&lt;/p&gt;

&lt;p&gt;Previously this peer-to-peer replica conflict would stall the whole operation until it was addressed.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Intelligent Query Processing
&lt;/h2&gt;

&lt;p&gt;Next generation of Intelligent Query Processing (IQP) includes solutions to some of the most common problems we face today, without any code changes required including:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;MAXDOP&lt;/code&gt; and &lt;code&gt;CE&lt;/code&gt; model feedback using the Query store to create a feedback cycle to automatically adapt and resolve problems with common query patterns.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Parameter Sensitive Query Plan Caching
&lt;/h2&gt;

&lt;p&gt;SQL Server has a great Query Optimizer, but one of the issue faced by a lot of people is Parameter Sniffing. SQL Server caches the execution plan for a Stored Procedure based on certain parameters (sniffing the parameters). This is usually good but it might not necessarily be efficient with another set of parameters.&lt;/p&gt;

&lt;p&gt;SQL Server 2022 introduces Parameter Sensitive Plan Optimization which can cache multiple plans based on parameters - without requiring any code change.&lt;/p&gt;

&lt;p&gt;Before revealing my top pick, let's see some honorable Mentions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Query Store is now turned on by default.&lt;/li&gt;
&lt;li&gt;Read Replica Support for Query Store - you can now use Query Store for your Read-Only workloads of your AG (Available Group).&lt;/li&gt;
&lt;li&gt;New extensions to the T-SQL language to support data virtualization and backup/restore with S3 compatible storage systems. Furthermore, T-SQL will support new JSON functions and time-series capabilities.&lt;/li&gt;
&lt;li&gt;Azure Synapse Link - Previously, moving data from on-premises databases, like SQL Server, to Synapse required you to use ETL. Azure Synapse Link for SQL Server 2022 provides automatic change feeds that capture the changes within SQL Server and feed those into Azure Synapse Analytics. It provides near real-time analysis and hybrid transactional and analytical processing with minimal impact on operational systems.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://azure.microsoft.com/en-in/services/purview/" rel="noopener noreferrer"&gt;Azure Purview&lt;/a&gt; Integration - Azure Purview as a unified data governance and management service. SQL Server 2022 is integrated with Azure Purview for greater data discovery, allowing you to break down data silos. Through this integration you will be able to:

&lt;ul&gt;
&lt;li&gt;Automatically scan your on-premises SQL Server for free to capture metadata.&lt;/li&gt;
&lt;li&gt;Classify data using built-in and custom classifiers and Microsoft Information Protection sensitivity labels.&lt;/li&gt;
&lt;li&gt;Set up and control specific access rights to SQL Server.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Now for the last feature:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Fully Managed Disaster Recovery in the Cloud
&lt;/h2&gt;

&lt;p&gt;Using SQL Server 2022 and the new link feature for Azure SQL Managed Instance, you now get all the benefits of running a PaaS environment applied to disaster recovery—allowing you to spend less time on setup and management even when compared to an IaaS environment. This works by using a built-in Distributed Availability Group (DAG) to replicate data to a previously deployed Azure SQL Managed Instance as a DR replica site. The instance is ready and waiting for whenever you need it—no lengthy configuration or maintenance is required. You can also use this link feature in read scale-out scenarios to offload heavy requests that might otherwise affect database performance. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3btdn6johmrdzga3bo3o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3btdn6johmrdzga3bo3o.png" alt="SQL Server Managed Cloud DR"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Did I miss any other cool feature? Let me know.&lt;/p&gt;

&lt;p&gt;Happy Coding! 👨‍💻&lt;/p&gt;

</description>
      <category>sql</category>
      <category>sqlserver</category>
      <category>sqlserver2022</category>
      <category>database</category>
    </item>
    <item>
      <title>How to Install Windows 11 on unsupported Devices - Officially - No Crack - No 3rd Party Tool</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Sun, 10 Oct 2021 07:40:47 +0000</pubDate>
      <link>https://dev.to/satish/how-to-install-windows-11-on-unsupported-devices-officially-no-crack-no-3rd-party-tool-10bn</link>
      <guid>https://dev.to/satish/how-to-install-windows-11-on-unsupported-devices-officially-no-crack-no-3rd-party-tool-10bn</guid>
      <description>&lt;p&gt;So you wanted the new Windows 11 everyone's talking about, but got a dreadful message liked that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This PC doesn't currently meet Windows 11 system requirements:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Unfortunately, you're not one of the lucky ones. Don't worry, we'll figure out a way together.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Check the &lt;a href="https://www.microsoft.com/en-in/windows/windows-11-specifications"&gt;Microsof's Official System Requirements for Windows 11&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now let's see how can you still install Windows 11. The answer is, of course - it depends. On what you don't have.&lt;/p&gt;

&lt;p&gt;I've categorized into 3 reason:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You don't have &lt;code&gt;TPM&lt;/code&gt; 2.0 (but do have 1.2 or other).&lt;/li&gt;
&lt;li&gt;You don't have any &lt;code&gt;TPM&lt;/code&gt;. But do have &lt;code&gt;Secure Boot&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;You don't even have &lt;code&gt;Secure Boot&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;What is &lt;a href="https://docs.microsoft.com/en-us/windows/security/information-protection/tpm/trusted-platform-module-top-node"&gt;&lt;code&gt;TPM (Trusted Platform Module)&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;How to find out which one do you have? Here's how, type following command on your &lt;code&gt;Command Prompt&lt;/code&gt; or &lt;code&gt;Run&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tpm.msc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't have any &lt;code&gt;TPM&lt;/code&gt;, following screen should pop up.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eoGhOMPd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/4049421/136685013-61d97061-b607-405d-add5-1db05f01370e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eoGhOMPd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/4049421/136685013-61d97061-b607-405d-add5-1db05f01370e.png" alt="image" width="348" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Otherwise, details of your &lt;code&gt;TPM&lt;/code&gt; would show up.&lt;/p&gt;

&lt;p&gt;Now, back to our solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solutions based on what you're missing
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. You don't have &lt;code&gt;TPM&lt;/code&gt; 2.0 (but do have &lt;code&gt;TPM&lt;/code&gt; 1.2 or other)
&lt;/h3&gt;

&lt;p&gt;Things are easier when you have some sort of &lt;code&gt;TPM&lt;/code&gt; e.g. 1.2 (but not 2.0). You just need to tell Windows - not to check for TPM 2.0. Wait, what? Yes!&lt;/p&gt;

&lt;p&gt;The usual disclaimer from Microsoft:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Serious problems might occur if you modify the registry incorrectly by using Registry Editor or by using another method. These problems might require that you reinstall the operating system. Microsoft cannot guarantee that these problems can be solved. Modify the registry at your own risk.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;1. Add the following registry setting in your existing Windows 10 Registry Editor:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Registry Key: HKEY_LOCAL_MACHINE&lt;span class="se"&gt;\S&lt;/span&gt;YSTEM&lt;span class="se"&gt;\S&lt;/span&gt;etup&lt;span class="se"&gt;\M&lt;/span&gt;oSetup

Name: AllowUpgradesWithUnsupportedTPMOrCPU

Type: REG_DWORD

Value: 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZkrMSQXD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/4049421/136685620-41497072-ba44-4bd5-a9de-53d4936e2b25.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZkrMSQXD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/4049421/136685620-41497072-ba44-4bd5-a9de-53d4936e2b25.png" alt="image" width="786" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1.2. Go to Windows 11 &lt;a href="https://www.microsoft.com/en-us/software-download/windows11"&gt;Create Windows 11 installation media&lt;/a&gt; page and follow the Official Instructions to create Bootable Media.&lt;br&gt;
1.3. Boot from this new media and you're good to go.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. If you don't have a any &lt;code&gt;TPM&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Follow the step #1.1 and step #1.2. But before booting from the new media, make note of follwing.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You need to change one more registry setting, not on your current Windows Installation, but after you boot from your new media. I'd recommend to open this blog post in another device for reference, or note it down.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since you don't have any sort of &lt;code&gt;TPM&lt;/code&gt;, add follwoing registry after booting from new media and BEFORE proceeding to "Install Now".&lt;/p&gt;

&lt;p&gt;2.1. Press Shift+F10 to open a &lt;code&gt;Command Prompt&lt;/code&gt;. Open registry editor by typing &lt;code&gt;regedit&lt;/code&gt;.&lt;br&gt;
2.2. Add new registry key named &lt;code&gt;LabConfig&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kf0jWtTY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/4049421/136686065-86d63f79-860a-4698-b2b0-092b04599dc9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kf0jWtTY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/4049421/136686065-86d63f79-860a-4698-b2b0-092b04599dc9.png" alt="image" width="217" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.3 Add new &lt;code&gt;DWORD&lt;/code&gt; named &lt;code&gt;BypassTPMCheck&lt;/code&gt; and change the value to &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nzQK9_-j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/4049421/136688280-6196e2bd-d973-4fe5-a9db-cf4b49489b44.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nzQK9_-j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/4049421/136688280-6196e2bd-d973-4fe5-a9db-cf4b49489b44.png" alt="image" width="800" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.4 Continue with the setup.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. If you don't have Secure Boot
&lt;/h3&gt;

&lt;p&gt;3.1. Follow till step# 2.3 and add a &lt;code&gt;DWORD&lt;/code&gt; named &lt;code&gt;BypassSecureBootCheck&lt;/code&gt; and change the value to &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AguKSfLI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/4049421/136688612-769fbdf9-0308-4bfc-986f-62206b95db14.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AguKSfLI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/4049421/136688612-769fbdf9-0308-4bfc-986f-62206b95db14.png" alt="image" width="800" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.2. Continue with the setup.&lt;/p&gt;

&lt;p&gt;And that's it! That wasn't so bad, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;Even though I've personally tested the instruction on my personal Windows 10 machine (without any TPM, but with Secure Boot). I am by no means responsible for any damage resulted by following instructions.&lt;/p&gt;

&lt;p&gt;Originally posted at &lt;a href="https://blog.satishyadav.com/How-to-Install-Windows-11-on-unsupported-Devices-Officially-No-Crack-No-3rd-Party-Tool/"&gt;https://blog.satishyadav.com/How-to-Install-Windows-11-on-unsupported-Devices-Officially-No-Crack-No-3rd-Party-Tool/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you liked this post, show some love to the GitHub repo by giving a star.&lt;br&gt;
&lt;a href="https://github.com/iSatishYadav/Windows11WithoutTPM"&gt;https://github.com/iSatishYadav/Windows11WithoutTPM&lt;/a&gt;&lt;/p&gt;

</description>
      <category>windows11</category>
      <category>windows</category>
      <category>tpm</category>
      <category>windows10</category>
    </item>
    <item>
      <title>Defense In-Depth: Designing an HTTP Content Length Restriction Middleware - ASP.NET 5 (or .NET Core)</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Sun, 22 Aug 2021 14:58:37 +0000</pubDate>
      <link>https://dev.to/satish/defense-in-depth-designing-an-http-content-length-restriction-middleware-asp-net-5-or-net-core-1cpp</link>
      <guid>https://dev.to/satish/defense-in-depth-designing-an-http-content-length-restriction-middleware-asp-net-5-or-net-core-1cpp</guid>
      <description>&lt;h2&gt;
  
  
  The What?
&lt;/h2&gt;

&lt;p&gt;We want to design a Middleware that - when plugged into an ASP.NET 5 (or .NET Core) application pipeline - restricts the input payload size, so attacks which rely of sending a bigger sized (or larger than our specified size) payload can be rejected by Application itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Why?
&lt;/h2&gt;

&lt;p&gt;You'd argue that &lt;em&gt;I have a firewall and other Security and Network devices so why do I need to implement this at Application level?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Well, if you follow Defence-in-Depth, &lt;a href="https://us-cert.cisa.gov/bsi/articles/knowledge/principles/defense-in-depth"&gt;US-CERT (United States Computer Emergency Readiness Team)&lt;/a&gt; has this to say about redundant security mechanisms:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Layering security defenses in an application can reduce the chance of a successful attack. Incorporating redundant security mechanisms requires an attacker to circumvent each mechanism to gain access to a digital asset. For example, a software system with authentication checks may prevent an attacker that has subverted a firewall. Defending an application with multiple layers can prevent a single point of failure that compromises the security of the application.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The How? - Let's code
&lt;/h2&gt;

&lt;p&gt;So I broken down this designing to 3 parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create the basic logic&lt;/li&gt;
&lt;li&gt;Make it a re-useable Middleware&lt;/li&gt;
&lt;li&gt;Make it look like a Native Middleware&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So let's get into it:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Create the basic logic
&lt;/h3&gt;

&lt;p&gt;We want to check the &lt;code&gt;ContentLength&lt;/code&gt; of &lt;code&gt;Request&lt;/code&gt; payload against our limit, if it exceeds, it should send the &lt;code&gt;HTTP 413 Entity Too Large&lt;/code&gt; as per &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.11"&gt;IETF RFC 7231&lt;/a&gt; specification of HTTP.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ContentLength&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;SOME_LIMIT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;    
    &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusCode&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StatusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status413RequestEntityTooLarge&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteAsJsonAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Title&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Request too large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;Status&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StatusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status413RequestEntityTooLarge&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://tools.ietf.org/html/rfc7231#section-6.5.11"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CompleteAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_requestDelegate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;

&lt;span class="n"&gt;Let&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;down&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;First&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt; &lt;span class="n"&gt;checking&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;If&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;greater&lt;/span&gt; &lt;span class="n"&gt;than&lt;/span&gt; &lt;span class="n"&gt;our&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt; &lt;span class="n"&gt;writing&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;JSON&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;HTTP&lt;/span&gt; &lt;span class="m"&gt;413&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}.&lt;/span&gt; &lt;span class="n"&gt;And&lt;/span&gt; &lt;span class="n"&gt;completing&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt; &lt;span class="n"&gt;don&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="n"&gt;need&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;execute&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt; &lt;span class="n"&gt;further&lt;/span&gt; &lt;span class="n"&gt;Middleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;If&lt;/span&gt; &lt;span class="n"&gt;not&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;Middleware&lt;/span&gt; &lt;span class="n"&gt;pipe&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="n"&gt;execute&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="n"&gt;Middleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="err"&gt;###&lt;/span&gt; &lt;span class="m"&gt;2.&lt;/span&gt; &lt;span class="n"&gt;Create&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;usable&lt;/span&gt; &lt;span class="n"&gt;middleware&lt;/span&gt;
&lt;span class="n"&gt;Now&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt; &lt;span class="n"&gt;have&lt;/span&gt; &lt;span class="n"&gt;our&lt;/span&gt; &lt;span class="n"&gt;basic&lt;/span&gt; &lt;span class="n"&gt;logic&lt;/span&gt; &lt;span class="n"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;usable&lt;/span&gt; &lt;span class="n"&gt;middleware&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;We&lt;/span&gt; &lt;span class="n"&gt;need&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="n"&gt;following&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="m"&gt;1.&lt;/span&gt; &lt;span class="n"&gt;Create&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;Middleware&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;and&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;our&lt;/span&gt; &lt;span class="n"&gt;logic&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;Invoke&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt; &lt;span class="n"&gt;or&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;InvokeAsync&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="m"&gt;2.&lt;/span&gt; &lt;span class="n"&gt;Take&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;runtime&lt;/span&gt; &lt;span class="n"&gt;instead&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;hard&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;coding&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="m"&gt;3.&lt;/span&gt; &lt;span class="n"&gt;Add&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;

&lt;span class="n"&gt;Let&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;complete&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;one&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;one&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="err"&gt;####&lt;/span&gt; &lt;span class="m"&gt;2.1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;  &lt;span class="n"&gt;Create&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;Middleware&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;and&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;our&lt;/span&gt; &lt;span class="n"&gt;logic&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;Invoke&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt; &lt;span class="n"&gt;or&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;InvokeAsync&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;Here&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;basic&lt;/span&gt; &lt;span class="n"&gt;structure&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;Middleware&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;looks&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;It&lt;/span&gt; &lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="n"&gt;have&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;Invoke&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt; &lt;span class="n"&gt;or&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;InvokeAsync&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="n"&gt;which&lt;/span&gt; &lt;span class="n"&gt;would&lt;/span&gt; &lt;span class="n"&gt;be&lt;/span&gt; &lt;span class="n"&gt;called&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;runtime&lt;/span&gt; &lt;span class="n"&gt;based&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;our&lt;/span&gt; &lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;


&lt;span class="err"&gt;````&lt;/span&gt;&lt;span class="n"&gt;csharp&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ContentLengthRestrictionMiddleware&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;RequestDelegate&lt;/span&gt; &lt;span class="n"&gt;_requestDelegate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;ContentLengthRestrictionMiddleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RequestDelegate&lt;/span&gt; &lt;span class="n"&gt;nextRequestDelegate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_requestDelegate&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nextRequestDelegate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;InvokeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HttpContext&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ContentLength&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;SOME_LIMIT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusCode&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StatusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status413RequestEntityTooLarge&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteAsJsonAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;Title&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Request too large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;Status&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StatusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status413RequestEntityTooLarge&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://tools.ietf.org/html/rfc7231#section-6.5.11"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CompleteAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_requestDelegate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;                  
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;

&lt;span class="err"&gt;####&lt;/span&gt; &lt;span class="m"&gt;2.2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;Take&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;runtime&lt;/span&gt; &lt;span class="n"&gt;instead&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;hard&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;coding&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;Currently&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt; &lt;span class="n"&gt;hard&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;coding&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="nf"&gt;limit&lt;/span&gt; &lt;span class="p"&gt;({%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;SOME_LIMIT&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}),&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;and&lt;/span&gt; &lt;span class="n"&gt;take&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;

&lt;span class="err"&gt;````&lt;/span&gt;&lt;span class="n"&gt;csharp&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ContentLengthRestrictionOptions&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;ContentLengthLimit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;

&lt;span class="n"&gt;And&lt;/span&gt; &lt;span class="n"&gt;modify&lt;/span&gt; &lt;span class="n"&gt;our&lt;/span&gt; &lt;span class="n"&gt;Middleware&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;use&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;


&lt;span class="err"&gt;````&lt;/span&gt;&lt;span class="n"&gt;csharp&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ContentLengthRestrictionMiddleware&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;ContentLengthRestrictionOptions&lt;/span&gt; &lt;span class="n"&gt;_contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;RequestDelegate&lt;/span&gt; &lt;span class="n"&gt;_requestDelegate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;ContentLengthRestrictionMiddleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RequestDelegate&lt;/span&gt; &lt;span class="n"&gt;nextRequestDelegate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ContentLengthRestrictionOptions&lt;/span&gt; &lt;span class="n"&gt;contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_requestDelegate&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nextRequestDelegate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;_contentLengthRestrictionOptions&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;InvokeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HttpContext&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_contentLengthRestrictionOptions&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;_contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ContentLengthLimit&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ContentLength&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ContentLengthLimit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusCode&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StatusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status413RequestEntityTooLarge&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteAsJsonAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;Title&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Request too large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;Status&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StatusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status413RequestEntityTooLarge&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://tools.ietf.org/html/rfc7231#section-6.5.11"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CompleteAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_requestDelegate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;


&lt;span class="err"&gt;####&lt;/span&gt; &lt;span class="m"&gt;2.3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;Add&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;

&lt;span class="n"&gt;Here&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;little&lt;/span&gt; &lt;span class="n"&gt;tricky&lt;/span&gt; &lt;span class="n"&gt;part&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="n"&gt;just&lt;/span&gt; &lt;span class="n"&gt;inject&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;ILogger&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="n"&gt;expect&lt;/span&gt; &lt;span class="n"&gt;runtime&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;give&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;that&lt;/span&gt; &lt;span class="n"&gt;dependency&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;ILoggerFactory&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="n"&gt;then&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;own&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;ILogger&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}.&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;


&lt;span class="err"&gt;````&lt;/span&gt;&lt;span class="n"&gt;csharp&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ContentLengthRestrictionMiddleware&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;ContentLengthRestrictionOptions&lt;/span&gt; &lt;span class="n"&gt;_contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;ILogger&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ContentLengthRestrictionMiddleware&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_logger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;RequestDelegate&lt;/span&gt; &lt;span class="n"&gt;_requestDelegate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;ContentLengthRestrictionMiddleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RequestDelegate&lt;/span&gt; &lt;span class="n"&gt;nextRequestDelegate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ContentLengthRestrictionOptions&lt;/span&gt; &lt;span class="n"&gt;contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ILoggerFactory&lt;/span&gt; &lt;span class="n"&gt;loggerFactory&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_requestDelegate&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nextRequestDelegate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;_contentLengthRestrictionOptions&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;_logger&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;loggerFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CreateLogger&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ContentLengthRestrictionMiddleware&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;InvokeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HttpContext&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_contentLengthRestrictionOptions&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;_contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ContentLengthLimit&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ContentLength&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ContentLengthLimit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;_logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;LogWarning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Rejecting request with Content-Length {0} more than allowed {1}."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ContentLength&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ContentLengthLimit&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusCode&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StatusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status413RequestEntityTooLarge&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteAsJsonAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;Title&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Request too large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;Status&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StatusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status413RequestEntityTooLarge&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://tools.ietf.org/html/rfc7231#section-6.5.11"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CompleteAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_requestDelegate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;httpContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;

&lt;span class="n"&gt;I&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;ve&lt;/span&gt; &lt;span class="n"&gt;added&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;log&lt;/span&gt; &lt;span class="n"&gt;only&lt;/span&gt; &lt;span class="n"&gt;when&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;Middleware&lt;/span&gt; &lt;span class="n"&gt;rejects&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="err"&gt;###&lt;/span&gt; &lt;span class="m"&gt;3.&lt;/span&gt; &lt;span class="n"&gt;Make&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;look&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;native&lt;/span&gt; &lt;span class="n"&gt;Middleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;We&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="n"&gt;Extension&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;IApplicationBuilder&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%},&lt;/span&gt; &lt;span class="n"&gt;something&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;UseXXX&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%},&lt;/span&gt; &lt;span class="n"&gt;so&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;feels&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;Native&lt;/span&gt; &lt;span class="n"&gt;Middleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;


&lt;span class="err"&gt;````&lt;/span&gt;&lt;span class="n"&gt;csharp&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MiddlewareExtensions&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IApplicationBuilder&lt;/span&gt; &lt;span class="nf"&gt;UseContentLengthRestriction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;IApplicationBuilder&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ContentLengthRestrictionOptions&lt;/span&gt; &lt;span class="n"&gt;contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UseMiddleware&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ContentLengthRestrictionMiddleware&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;contentLengthRestrictionOptions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;

&lt;span class="n"&gt;And&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="n"&gt;use&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;


&lt;span class="err"&gt;````&lt;/span&gt;&lt;span class="n"&gt;csharp&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Configure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IApplicationBuilder&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IWebHostEnvironment&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//This is our Middleware 😍&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseContentLengthRestriction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;ContentLengthRestrictionOptions&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;ContentLengthLimit&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="c1"&gt;/// Other configuration&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsDevelopment&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseDeveloperExceptionPage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseHttpsRedirection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseRouting&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseAuthorization&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseEndpoints&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;endpoints&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;endpoints&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapControllers&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;


&lt;span class="err"&gt;##&lt;/span&gt; &lt;span class="m"&gt;4.&lt;/span&gt; &lt;span class="n"&gt;The&lt;/span&gt; &lt;span class="n"&gt;Execution&lt;/span&gt;
&lt;span class="n"&gt;Sending&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="n"&gt;POST&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;our&lt;/span&gt; &lt;span class="n"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;

&lt;span class="err"&gt;````&lt;/span&gt;&lt;span class="n"&gt;curl&lt;/span&gt;
&lt;span class="n"&gt;curl&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt; &lt;span class="n"&gt;POST&lt;/span&gt; &lt;span class="s"&gt;"https://localhost:5001/WeatherForecast"&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;H&lt;/span&gt;  &lt;span class="s"&gt;"accept: */*"&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;H&lt;/span&gt;  &lt;span class="s"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="s"&gt;"{\"date\":\"2021-08-22T14:17:58.115Z\",\"temperatureC\":0,\"summary\":\"string\"}"&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;


&lt;span class="n"&gt;Results&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;following&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;

&lt;span class="err"&gt;````&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Request too large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;413&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"https://tools.ietf.org/html/rfc7231#section-6.5.11"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;endraw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;


&lt;span class="n"&gt;And&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="n"&gt;following&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="p"&gt;{%&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="p"&gt;%}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;warn: AwesomeApi.ContentLengthRestrictionMiddleware[0]&lt;br&gt;
      Rejecting request with Content-Length 71 more than allowed 10.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


## Conclusion
That's it! Congratulations! You just designed and created a custom Middleware! Give yourself a pat in the back. Don't forget to stretch your shoulders and neck once in a while.

Happy Coding!

## Code
Source Code is available at:
[https://github.com/iSatishYadav/ContentLengthRestrictionMiddleware](https://github.com/iSatishYadav/ContentLengthRestrictionMiddleware)

If you liked it, go show some love to the repo and star it. 

Originally Posted at my blog:
[https://blog.satishyadav.com/defense-in-depth-designing-an-http-content-length-restriction-middleware-asp-net-5-or-net-core](https://blog.satishyadav.com/defense-in-depth-designing-an-http-content-length-restriction-middleware-asp-net-5-or-net-core?utm_source=dt)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>defenceindepth</category>
      <category>aspnet5</category>
      <category>middleware</category>
    </item>
    <item>
      <title>How to setup and use DynamoDb Locally - Free</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Tue, 06 Jul 2021 15:41:54 +0000</pubDate>
      <link>https://dev.to/satish/how-to-setup-and-use-dynamodb-locally-free-4mo9</link>
      <guid>https://dev.to/satish/how-to-setup-and-use-dynamodb-locally-free-4mo9</guid>
      <description>&lt;p&gt;Did you know DynamoDB from AWS has a locally downloadable version which you can install on your local machine and use for development and testing purposes.&lt;/p&gt;

&lt;p&gt;As a newbie to AWS, I was unable to find any comprehensive guide on how to setup and use DynamoDB locally. So without further ado, let's start.&lt;/p&gt;

&lt;h2&gt;
  
  
  Download the DynamoDB Local (Downloadable Version)
&lt;/h2&gt;

&lt;p&gt;There are 3 ways you can download:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Standalone &lt;code&gt;jar&lt;/code&gt; file&lt;/li&gt;
&lt;li&gt;Using &lt;code&gt;Docker&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Using an &lt;code&gt;Apache Maven&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I'm using Docker for this tutorial, for instructions on other 2 ways, visit this official &lt;a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html"&gt;AWS site&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please note your application doesn't have to be a containerized application, we're just using DynamoDB database as a container, that's it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Using &lt;code&gt;Docker&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Make sure you have docker up and running. If you've not, follow this &lt;a href="https://docs.docker.com/desktop/"&gt;official instructions&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-p&lt;/span&gt; 8000:8000 amazon/dynamodb-local
&lt;span class="sb"&gt;```&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;

This will download &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;DynamoDB&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt; locally from official Docker image and run.
If everything is okay, you&lt;span class="s1"&gt;'d see output something like this:

`

```shell
Initializing DynamoDB Local with the following configuration:
Port:   8000
InMemory:       true
DbPath: null
SharedDb:       false
shouldDelayTransientStatuses:   false
CorsParams:     *
```

`

This would run the fully functional DynamoDB instance at `http://localhost:8000`.

## [Bonus] Verify installation using AWS CLI.
If don'&lt;/span&gt;t have AWS CLI installed, follow &lt;span class="o"&gt;[&lt;/span&gt;this official guide]&lt;span class="o"&gt;(&lt;/span&gt;https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html&lt;span class="o"&gt;)&lt;/span&gt;

Run this &lt;span class="nb"&gt;command &lt;/span&gt;to verify the installation

&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="sb"&gt;```&lt;/span&gt;shell
aws dynamodb list-tables &lt;span class="nt"&gt;--endpoint-url&lt;/span&gt; http://localhost:8000
&lt;span class="sb"&gt;```&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;

If you get an error like this:
&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="sb"&gt;```&lt;/span&gt;shell
You must specify a region. You can also configure your region by running &lt;span class="s2"&gt;"aws configure"&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
&lt;span class="sb"&gt;```&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
You can run:

&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="sb"&gt;```&lt;/span&gt;shell 
aws configure
&lt;span class="sb"&gt;```&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% endraw %&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;% raw %&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
And you&lt;span class="s1"&gt;'d be asked to setup follwoing:

`

```shell
AWS Access Key ID:
AWS Secret Access Key :
Default region name [x]:
Default output format [None]:
```

`
You can enter any values, as you'&lt;/span&gt;re only using DynamoDB locally.

That&lt;span class="s1"&gt;'s it!

That'&lt;/span&gt;s how you can configure AWS DynamoDB on your &lt;span class="nb"&gt;local &lt;/span&gt;machine to develop and &lt;span class="nb"&gt;test &lt;/span&gt;your applications without spending anything.

Happy Coding!

Originally posted at my blog: &lt;span class="o"&gt;[&lt;/span&gt;https://blog.satishyadav.com/how-to-setup-and-use-dynamodb-locally-free]&lt;span class="o"&gt;(&lt;/span&gt;https://shawt.io/r/sYW&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>dynamodb</category>
      <category>aws</category>
      <category>docker</category>
    </item>
    <item>
      <title>.NET 6 LINQ New Features</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Sun, 04 Jul 2021 15:33:16 +0000</pubDate>
      <link>https://dev.to/satish/net-6-linq-new-features-opb</link>
      <guid>https://dev.to/satish/net-6-linq-new-features-opb</guid>
      <description>&lt;h2&gt;
  
  
  What is &lt;code&gt;.NET 6&lt;/code&gt; and why should I care?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;.NET 6&lt;/code&gt; is the upcoming major overhaul for &lt;code&gt;.NET&lt;/code&gt;. It unifies entire &lt;code&gt;.NET&lt;/code&gt; experience. No more &lt;code&gt;.NET Core&lt;/code&gt;, &lt;code&gt;.NET Full Framework&lt;/code&gt;, &lt;code&gt;Xamarin&lt;/code&gt;, &lt;code&gt;Mono&lt;/code&gt;, etc. Just a single &lt;code&gt;.NET&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  New &lt;code&gt;LINQ&lt;/code&gt; Features
&lt;/h2&gt;

&lt;p&gt;At the time of writing this post, 5 previews of &lt;code&gt;.NET 6&lt;/code&gt; have been released and last couple of releases have been blessing for &lt;code&gt;LINQ&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here are few top new &lt;code&gt;LINQ&lt;/code&gt; features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;New methods &lt;code&gt;MaxBy&lt;/code&gt; and &lt;code&gt;MinBy&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;New methods &lt;code&gt;Chunk&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;New methods &lt;code&gt;DistinctBy&lt;/code&gt;, &lt;code&gt;UnionBy&lt;/code&gt;, &lt;code&gt;IntersectBy&lt;/code&gt;, and &lt;code&gt;ExceptBy&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Index&lt;/code&gt; and &lt;code&gt;Range&lt;/code&gt; parameters&lt;/li&gt;
&lt;li&gt;New method &lt;code&gt;TryGetNonEnumeratedCount&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Default parameters for &lt;code&gt;FirstOrDefault&lt;/code&gt;, &lt;code&gt;LastOrDefault&lt;/code&gt;, and &lt;code&gt;SingleOrDefault&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Zip&lt;/code&gt; supports 3 &lt;code&gt;IEnumerables&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  New methods &lt;code&gt;MaxBy&lt;/code&gt; and &lt;code&gt;MinBy&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Finding out maximum or minimum has been easier than even with these new &lt;code&gt;MaxBy&lt;/code&gt; or &lt;code&gt;MinBy&lt;/code&gt; methods.&lt;/p&gt;

&lt;p&gt;Suppose a &lt;code&gt;List&lt;/code&gt; of &lt;code&gt;Person&lt;/code&gt;s as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Amit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Age&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;38&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Ravi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Age&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;36&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Manish"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Age&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;34&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Satish"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Age&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;29&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we need to get maximum and minimum, currently here's how to do it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Without using MaxBy and MinBy&lt;/span&gt;
&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;oldestPerson&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;OrderByDescending&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;First&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;youngestPerson&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;OrderBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;First&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Oldest Person without using MaxBy: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;oldestPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Youngest Person without using MaxBy: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;youngestPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But with &lt;code&gt;MaxBy&lt;/code&gt; and &lt;code&gt;MinBy&lt;/code&gt;, it's just a single method call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;oldestPerson&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MaxBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;youngestPerson&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MinBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Oldest Person using MaxBy: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;oldestPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Youngest Person using MaxBy: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;youngestPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neat, right? Let me know in the comments, if you have alternate methods of getting maximum and minimum using &lt;code&gt;LINQ&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  New method &lt;code&gt;Chunk&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;A new method &lt;code&gt;Chunk&lt;/code&gt; slices the &lt;code&gt;IEnumerable&lt;/code&gt; into provided sizes. e.g. If you have a collection of 4 elements and you need to cluster them into fixed size of 2, here's how to do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;]&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;cluster&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Chunk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Print each cluster.&lt;/span&gt;
&lt;span class="k"&gt;foreach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;cluster&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Cluster of &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;","&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;))}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;//Prints&lt;/span&gt;
&lt;span class="c1"&gt;// Cluster of Amit,Ravi&lt;/span&gt;
&lt;span class="c1"&gt;// Cluster of Manish,Satish&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  New methods &lt;code&gt;DistinctBy&lt;/code&gt;, &lt;code&gt;UnionBy&lt;/code&gt;, &lt;code&gt;IntersectBy&lt;/code&gt;, and &lt;code&gt;ExceptBy&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Exisiting set methods &lt;code&gt;Distinct&lt;/code&gt;, &lt;code&gt;Union&lt;/code&gt;, &lt;code&gt;Intersect&lt;/code&gt;, and &lt;code&gt;Except&lt;/code&gt; have been powered up by these new methods which can take a selector function to operate.&lt;br&gt;
e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;evenAgedPeople&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Amit,Ravi,Manish&lt;/span&gt;

&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;personAbove35&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;35&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Amit,Ravi&lt;/span&gt;

&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;union&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;evenAgedPeople&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UnionBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;personAbove35&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Amit,Ravi,Manish&lt;/span&gt;

&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;intersection&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;evenAgedPeople&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IntersectBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;personAbove35&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Amit,Ravi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me know in the comments, the usage of &lt;code&gt;DistinctBy&lt;/code&gt; and &lt;code&gt;ExceptBy&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;Index&lt;/code&gt; and &lt;code&gt;Range&lt;/code&gt; parameters
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Range&lt;/code&gt;: &lt;code&gt;..&lt;/code&gt;, and &lt;code&gt;Index&lt;/code&gt;: &lt;code&gt;^&lt;/code&gt; already exist in &lt;code&gt;C#&lt;/code&gt;8, &lt;code&gt;.NET 6&lt;/code&gt; brings these two to &lt;code&gt;LINQ&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;ElementAt&lt;/code&gt; operator now takes indices from the end.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;secondLastPerson&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ElementAt&lt;/span&gt;&lt;span class="p"&gt;(^&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Manish&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Skip&lt;/code&gt; and &lt;code&gt;Take&lt;/code&gt; now take &lt;code&gt;Range&lt;/code&gt; as well:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;take3People&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Take&lt;/span&gt;&lt;span class="p"&gt;(..&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Amit,Ravi,Manish&lt;/span&gt;

&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;skip1Person&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Take&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.&lt;/span&gt;&lt;span class="p"&gt;.);&lt;/span&gt;
&lt;span class="c1"&gt;//Ravi,Manish,Satish&lt;/span&gt;

&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;take3Skip1People&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Take&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Ravi,Manish&lt;/span&gt;

&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;takeLast2People&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Take&lt;/span&gt;&lt;span class="p"&gt;(^&lt;/span&gt;&lt;span class="m"&gt;2.&lt;/span&gt;&lt;span class="p"&gt;.);&lt;/span&gt;
&lt;span class="c1"&gt;//Manish,Satish&lt;/span&gt;

&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;skipLast3People&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Take&lt;/span&gt;&lt;span class="p"&gt;(..^&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Amit&lt;/span&gt;

&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;takeLast3SkipLast2&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Take&lt;/span&gt;&lt;span class="p"&gt;(^&lt;/span&gt;&lt;span class="m"&gt;3.&lt;/span&gt;&lt;span class="p"&gt;.^&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Ravi&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  New method &lt;code&gt;TryGetNonEnumeratedCount&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Sometimes you need to get a count without the enumeration. &lt;code&gt;TryGetNonEnumeratedCount&lt;/code&gt; will try to get count without forcing an enumeration. It internally checks for the implementation of &lt;code&gt;ICollection&lt;/code&gt; i.e. &lt;code&gt;IEnumerable&lt;/code&gt; that already has a mechanism to get count without forcing an enumeration. Otherwise it'll try to take advantage of new improvements in &lt;code&gt;LINQ&lt;/code&gt;.&lt;br&gt;
Useful in scenarios where you want to get a count but not at the cost of enumerating the &lt;code&gt;IEnumerable&lt;/code&gt;.&lt;br&gt;
e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;anotherList&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TryGetNonEnumeratedCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;span class="n"&gt;anotherList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddRange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our case right now, we know that people is just an in-memory list, but what if it was from database of some &lt;code&gt;Stream&lt;/code&gt;, then it would've made sense to find out the count to optimize the instantiation of &lt;code&gt;anotherList&lt;/code&gt; object by specifying &lt;code&gt;capacity&lt;/code&gt; parameter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Default parameters for &lt;code&gt;FirstOrDefault&lt;/code&gt;, &lt;code&gt;LastOrDefault&lt;/code&gt;, and &lt;code&gt;SingleOrDefault&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Current &lt;code&gt;FirstOrDefault&lt;/code&gt;, &lt;code&gt;LastOrDefault&lt;/code&gt;, and &lt;code&gt;SingleOrDefault&lt;/code&gt; methods return &lt;code&gt;default(T)&lt;/code&gt; if the source &lt;code&gt;IEnumerable&lt;/code&gt; is empty. The new overloads accept a parameter which will be returned if source is empty.&lt;/p&gt;

&lt;p&gt;e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;emptyList&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;emptyList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FirstOrDefault&lt;/span&gt;&lt;span class="p"&gt;(-&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//-1 instead of 0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reminds me of &lt;code&gt;ISNULL&lt;/code&gt; function of &lt;code&gt;SQL Server&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;Zip&lt;/code&gt; supports 3 &lt;code&gt;IEnumerables&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Before &lt;code&gt;.NET 6&lt;/code&gt;, &lt;a href="https://docs.microsoft.com/en-gb/dotnet/api/system.linq.enumerable.zip?view=net-5.0"&gt;&lt;code&gt;Zip&lt;/code&gt;&lt;/a&gt; used to take only 2 parameters. Now it takes 3 parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ids&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Enumerable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;allPeople&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;allAges&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="p"&gt;)&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;zipped&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Zip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;allPeople&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;allAges&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;.NET 6&lt;/code&gt; previews are bring awesome set of new features with every new release. Let me know in comments which all features you're excited for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Download &lt;a href="https://dotnet.microsoft.com/download/dotnet/6.0"&gt;&lt;code&gt;.NET 6&lt;/code&gt;&lt;/a&gt; today and try out.&lt;/li&gt;
&lt;li&gt;Source code is available at: &lt;a href="https://shawt.io/r/sYT"&gt;https://github.com/iSatishYadav/.net-6-linq-new-features&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published at my blog at: &lt;a href="https://shawt.io/r/sYS"&gt;https://blog.satishyadav.com/.net-6-linq-new-features&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>linq</category>
      <category>dotnet6</category>
      <category>net6</category>
    </item>
    <item>
      <title>Visual Studio 2022 will write code for you!!! - Visual Studio 2022 Series - Part 1</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Sun, 20 Jun 2021 11:15:11 +0000</pubDate>
      <link>https://dev.to/satish/visual-studio-2022-will-write-code-for-you-visual-studio-2022-series-part-1-4dl2</link>
      <guid>https://dev.to/satish/visual-studio-2022-will-write-code-for-you-visual-studio-2022-series-part-1-4dl2</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Visual Studio 2022 Preview 1 is now available! If you've missed the &lt;a href="https://devblogs.microsoft.com/visualstudio/visual-studio-2022-preview-1-now-available/" rel="noopener noreferrer"&gt;official announcement&lt;/a&gt; on June 17th, 2021 - check it out.&lt;br&gt;
If you want to try out, head over to the official download page &lt;a href="https://visualstudio.microsoft.com/vs/preview/vs2022/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The Visual Studio 2022 previews can be installed side-by-side with earlier versions of Visual Studio, are available in all three editions (Community, Pro, and Enterprise), and are free to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  New Features
&lt;/h2&gt;

&lt;p&gt;A lot of new features have come out in this release, however Visual Studio 2022 is just out with Preview 1, meaning there will be more and more new features coming in new Previews.&lt;/p&gt;

&lt;p&gt;But today I want to talk about 2 of my favorite features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;64-bit&lt;/li&gt;
&lt;li&gt;IntelliCode&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  64-bit
&lt;/h3&gt;

&lt;p&gt;The first and the biggest feature is - and boy, that's big one - it's 64-bit!!! 😍 This means - Visual Studio 2022 will no longer be limited to ~4gb of memory in the main &lt;code&gt;devenv.exe&lt;/code&gt; process. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FiSatishYadav%2FVisual-Studio-2022-will-write-code-for-you%2Fmaster%2Fimages%2Fvs2022-64bit.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FiSatishYadav%2FVisual-Studio-2022-will-write-code-for-you%2Fmaster%2Fimages%2Fvs2022-64bit.png" alt="Visual Studio 2022 64-bit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Microsoft's own words:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;With a 64-bit Visual Studio on Windows, you can open, edit, run, and debug even the biggest and most complex solutions without running out of memory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This doesn't mean you can't develop 32-bit applications using Visual Studio 2022, it just means the Visual Studio itself wil be able to fully utilize your 64-bit hardware.&lt;/p&gt;

&lt;h3&gt;
  
  
  IntelliCode - one step further
&lt;/h3&gt;

&lt;p&gt;This one's my favorite new feature. We all know and love &lt;a href="https://visualstudio.microsoft.com/services/intellicode/" rel="noopener noreferrer"&gt;IntelliCode&lt;/a&gt; - Microsoft's AI enabled Visual Studio component which suggests code changes using Machine Learning Model based on 1000s of Open-Source GitHub repositories and optionally your own repositories if you permit.&lt;/p&gt;

&lt;p&gt;In Visual Studio 2022, IntelliCode has gone one step further and not only will suggest the code changes, it'll will write the code for you 😲. Look at this GIF:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FiSatishYadav%2FVisual-Studio-2022-will-write-code-for-you%2Fmaster%2Fimages%2FVisualStudio2022IntelliCode.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FiSatishYadav%2FVisual-Studio-2022-will-write-code-for-you%2Fmaster%2Fimages%2FVisualStudio2022IntelliCode.gif" alt="Visual Studio 2022 G4-bit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As soon as I write &lt;code&gt;StringBuilder&lt;/code&gt; it knows what I'm about to write and with the &lt;code&gt;TAB&lt;/code&gt; press, it writes &lt;code&gt;StringBuilder sb = new StringBuilder();&lt;/code&gt; for me. &lt;/li&gt;
&lt;li&gt;Similarly in the &lt;code&gt;foreach&lt;/code&gt; loop, it know I'm going to append the &lt;code&gt;item&lt;/code&gt; to the &lt;code&gt;StringBuilder&lt;/code&gt; and writes &lt;code&gt;sb.Append(item)&lt;/code&gt; for me.&lt;/li&gt;
&lt;li&gt;Finally after the loop it knows I want to print it, so it prints using &lt;code&gt;Console.WriteLine&lt;/code&gt; by calling &lt;code&gt;ToString()&lt;/code&gt; on the &lt;code&gt;StringBuilder&lt;/code&gt; reference &lt;code&gt;sb&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cool, right!!!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This is just a Preview 1, there will be at-lest 4-5 previews before it hits GA - General Availability. So watch out for more posts.&lt;/p&gt;

&lt;p&gt;Let me know which all features ya'll are excited for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Read more about &lt;a href="https://visualstudio.microsoft.com/services/intellicode/" rel="noopener noreferrer"&gt;IntelliCode&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Check out the &lt;a href="https://devblogs.microsoft.com/visualstudio/visual-studio-2022-preview-1-now-available/" rel="noopener noreferrer"&gt;Official announcement&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Download &lt;a href="https://visualstudio.microsoft.com/vs/preview/vs2022/" rel="noopener noreferrer"&gt;Visual Studio 2022&lt;/a&gt; and try now.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally Posted at: &lt;a href="https://blog.satishyadav.com/Visual-Studio-2022-will-write-code-for-you/" rel="noopener noreferrer"&gt;https://blog.satishyadav.com/Visual-Studio-2022-will-write-code-for-you/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy Coding! 👨‍💻&lt;/p&gt;

</description>
      <category>visualstudio2022</category>
      <category>visualstudio</category>
      <category>vs2022</category>
    </item>
    <item>
      <title>Using NLog in a .NET 5 Console Application with Dependency Injection and send logs to AWS CloudWatch</title>
      <dc:creator>Satish Yadav</dc:creator>
      <pubDate>Sat, 22 May 2021 09:04:23 +0000</pubDate>
      <link>https://dev.to/satish/using-nlog-in-a-net-5-console-application-with-dependency-injection-52mm</link>
      <guid>https://dev.to/satish/using-nlog-in-a-net-5-console-application-with-dependency-injection-52mm</guid>
      <description>&lt;h2&gt;
  
  
  Description
&lt;/h2&gt;

&lt;p&gt;Explains how to setup NLog as logging provider for .NET 5 Console Application and Dependency Injection).&lt;/p&gt;

&lt;p&gt;Demonstrated with a .NET 5 Console application. Example project can also be found on &lt;a href="https://github.com/iSatishYadav/net-core-console-nlog-with-di"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  0. Create a new .NET 5 console project
&lt;/h3&gt;

&lt;h3&gt;
  
  
  1. Add dependency in csproj manually or using NuGet
&lt;/h3&gt;

&lt;p&gt;Install:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The package &lt;a href="https://www.nuget.org/packages/NLog.Extensions.Logging"&gt;NLog.Extensions.Logging&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The package &lt;a href="https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection"&gt;Microsoft.Extensions.DependencyInjection&lt;/a&gt; - or use another DI library.&lt;/li&gt;
&lt;li&gt;The package &lt;a href="https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Json"&gt;Microsoft.Extensions.Configuration.Json&lt;/a&gt; (used in Main method &lt;code&gt;SetBasePath&lt;/code&gt; + &lt;code&gt;AddJsonFile&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Update the NLog package if possible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;ItemGroup&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include=&lt;/span&gt;&lt;span class="s"&gt;"Microsoft.Extensions.Configuration.Json"&lt;/span&gt; &lt;span class="na"&gt;Version=&lt;/span&gt;&lt;span class="s"&gt;"2.1.0"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include=&lt;/span&gt;&lt;span class="s"&gt;"Microsoft.Extensions.DependencyInjection"&lt;/span&gt; &lt;span class="na"&gt;Version=&lt;/span&gt;&lt;span class="s"&gt;"2.1.0"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include=&lt;/span&gt;&lt;span class="s"&gt;"NLog"&lt;/span&gt; &lt;span class="na"&gt;Version=&lt;/span&gt;&lt;span class="s"&gt;"4.6.5"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include=&lt;/span&gt;&lt;span class="s"&gt;"NLog.Extensions.Logging"&lt;/span&gt; &lt;span class="na"&gt;Version=&lt;/span&gt;&lt;span class="s"&gt;"1.5.1"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ItemGroup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Create a nlog.config file.
&lt;/h3&gt;

&lt;p&gt;Create nlog.config (lowercase all) file in the root of your application project (File Properties: Copy Always)&lt;/p&gt;

&lt;p&gt;We use this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- XSD manual extracted from package NLog.Schema: https://www.nuget.org/packages/NLog.Schema--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;nlog&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"http://www.nlog-project.org/schemas/NLog.xsd"&lt;/span&gt; &lt;span class="na"&gt;xsi:schemaLocation=&lt;/span&gt;&lt;span class="s"&gt;"NLog NLog.xsd"&lt;/span&gt;
      &lt;span class="na"&gt;xmlns:xsi=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt;
      &lt;span class="na"&gt;autoReload=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;
      &lt;span class="na"&gt;internalLogFile=&lt;/span&gt;&lt;span class="s"&gt;"c:\temp\skylogs\nlog-internal.log"&lt;/span&gt;
      &lt;span class="na"&gt;internalLogLevel=&lt;/span&gt;&lt;span class="s"&gt;"Info"&lt;/span&gt; &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="c"&gt;&amp;lt;!-- the targets to write to --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;targets&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- write logs to file --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;target&lt;/span&gt; &lt;span class="na"&gt;xsi:type=&lt;/span&gt;&lt;span class="s"&gt;"File"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"logfile"&lt;/span&gt; &lt;span class="na"&gt;fileName=&lt;/span&gt;&lt;span class="s"&gt;"c:\temp\skylogs\skylogs.log"&lt;/span&gt;
            &lt;span class="na"&gt;layout=&lt;/span&gt;&lt;span class="s"&gt;"${longdate}|${level}|${message} |${all-event-properties} ${exception:format=tostring}"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;target&lt;/span&gt; &lt;span class="na"&gt;xsi:type=&lt;/span&gt;&lt;span class="s"&gt;"Console"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"logconsole"&lt;/span&gt;
            &lt;span class="na"&gt;layout=&lt;/span&gt;&lt;span class="s"&gt;"${longdate}|${level}|${message} |${all-event-properties} ${exception:format=tostring}"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/targets&amp;gt;&lt;/span&gt;

  &lt;span class="c"&gt;&amp;lt;!-- rules to map from logger name to target --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;rules&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;logger&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"*"&lt;/span&gt; &lt;span class="na"&gt;minlevel=&lt;/span&gt;&lt;span class="s"&gt;"Trace"&lt;/span&gt; &lt;span class="na"&gt;writeTo=&lt;/span&gt;&lt;span class="s"&gt;"logfile,logconsole"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/rules&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/nlog&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is recommended to read the &lt;a href="https://github.com/NLog/NLog/wiki/Tutorial"&gt;NLog Tutorial&lt;/a&gt;. For more detailed information about config file can be found &lt;a href="https://github.com/NLog/NLog/wiki/Configuration-file"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you like to include other targets or layout renderers, check the &lt;a href="https://github.com/NLog/NLog/wiki/platform-support"&gt;Platform support&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Ensure to configure your project-file to copy NLog.config to the output directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt; &lt;span class="nt"&gt;&amp;lt;ItemGroup&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;None&lt;/span&gt; &lt;span class="na"&gt;Update=&lt;/span&gt;&lt;span class="s"&gt;"nlog.config"&lt;/span&gt; &lt;span class="na"&gt;CopyToOutputDirectory=&lt;/span&gt;&lt;span class="s"&gt;"Always"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;/ItemGroup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Update your program
&lt;/h3&gt;

&lt;h4&gt;
  
  
  3.1 Create your Person class
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;ILogger&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_logger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ILogger&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;_logger&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Talk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="n"&gt;_logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;LogInformation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Person {name} spoke {text}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3.2 Setup the Dependency injector (DI) container
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IServiceProvider&lt;/span&gt; &lt;span class="nf"&gt;BuildDi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IConfiguration&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ServiceCollection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
           &lt;span class="c1"&gt;//Add DI Classes here&lt;/span&gt;
         &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddTransient&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;()&lt;/span&gt; 
         &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddLogging&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;loggingBuilder&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
         &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="c1"&gt;// configure Logging with NLog&lt;/span&gt;
             &lt;span class="n"&gt;loggingBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ClearProviders&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
             &lt;span class="n"&gt;loggingBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SetMinimumLevel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Extensions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LogLevel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Trace&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
             &lt;span class="n"&gt;loggingBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddNLog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
         &lt;span class="p"&gt;})&lt;/span&gt;
         &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;BuildServiceProvider&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3.3 Add required usings
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Microsoft.Extensions.Configuration&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Microsoft.Extensions.DependencyInjection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Microsoft.Extensions.Logging&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;NLog&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;NLog.Extensions.Logging&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3.4 Update your &lt;code&gt;Main()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;First create the DI container, then get your &lt;code&gt;Person&lt;/code&gt; and start running!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;LogManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetCurrentClassLogger&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ConfigurationBuilder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
           &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SetBasePath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IO&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Directory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetCurrentDirectory&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
           &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddJsonFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"appsettings.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reloadOnChange&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;servicesProvider&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;BuildDi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;servicesProvider&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;IDisposable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;servicesProvider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetRequiredService&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
            &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Sky"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Talk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Press ANY key to exit"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadKey&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// NLog: catch any exception and log it.&lt;/span&gt;
        &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Stopped program because of exception"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;finally&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)&lt;/span&gt;
        &lt;span class="n"&gt;LogManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Shutdown&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IServiceProvider&lt;/span&gt; &lt;span class="nf"&gt;BuildDi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IConfiguration&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ServiceCollection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
         &lt;span class="c1"&gt;//Add DI Classes here&lt;/span&gt;
       &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddTransient&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Runner is the custom class&lt;/span&gt;
       &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddLogging&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;loggingBuilder&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
       &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="c1"&gt;// configure Logging with NLog&lt;/span&gt;
           &lt;span class="n"&gt;loggingBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ClearProviders&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
           &lt;span class="n"&gt;loggingBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SetMinimumLevel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Extensions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LogLevel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Trace&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
           &lt;span class="n"&gt;loggingBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddNLog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
       &lt;span class="p"&gt;})&lt;/span&gt;
       &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;BuildServiceProvider&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4 Example output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2021-05-22 12:33:20.8486|Info|Person Sky spoke Hello |name=Sky, text=Hello 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Send Logs to AWS CloudWatch
&lt;/h2&gt;

&lt;p&gt;Here's a sample nlog.config to send NLog logs directly to CloudWatch Logs log group.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;nlog&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"http://www.nlog-project.org/schemas/NLog.xsd"&lt;/span&gt;
      &lt;span class="na"&gt;xmlns:xsi=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt;
      &lt;span class="na"&gt;throwConfigExceptions=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;extensions&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;add&lt;/span&gt; &lt;span class="na"&gt;assembly=&lt;/span&gt;&lt;span class="s"&gt;"NLog.AWS.Logger"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/extensions&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;targets&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;target&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"aws"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"AWSTarget"&lt;/span&gt; &lt;span class="na"&gt;logGroup=&lt;/span&gt;&lt;span class="s"&gt;"NLog.ConfigExample"&lt;/span&gt; &lt;span class="na"&gt;region=&lt;/span&gt;&lt;span class="s"&gt;"us-east-1"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/targets&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;rules&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;logger&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"*"&lt;/span&gt; &lt;span class="na"&gt;minlevel=&lt;/span&gt;&lt;span class="s"&gt;"Info"&lt;/span&gt; &lt;span class="na"&gt;writeTo=&lt;/span&gt;&lt;span class="s"&gt;"aws"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/rules&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/nlog&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The AWS credentials will be found using the standard AWS SDK for .NET credentials search path. In this case it will look for a profile named default, search for environment variables or search for an instance profile on an EC2 instance. To use a specific AWS credential profile use the profile attribute on the target.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure NLog Targets for output
&lt;/h2&gt;

&lt;p&gt;Next step, see &lt;a href="https://github.com/NLog/NLog/wiki/Configuration-file"&gt;Configure NLog with nlog.config&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Originally posted at: &lt;br&gt;
&lt;a href="https://blog.satishyadav.com/net-core-console-nlog-with-di/"&gt;https://blog.satishyadav.com/net-core-console-nlog-with-di/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nlog</category>
      <category>net5</category>
      <category>dependencyinjection</category>
      <category>consoleapp</category>
    </item>
  </channel>
</rss>
