<?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: Sergei Belialov</title>
    <description>The latest articles on DEV Community by Sergei Belialov (@godszerg86).</description>
    <link>https://dev.to/godszerg86</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%2F299877%2F3958de34-0578-40a4-9bf4-5759961a2d64.jpeg</url>
      <title>DEV Community: Sergei Belialov</title>
      <link>https://dev.to/godszerg86</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/godszerg86"/>
    <language>en</language>
    <item>
      <title>Quick and easy DbContext setup in .NET</title>
      <dc:creator>Sergei Belialov</dc:creator>
      <pubDate>Sun, 21 May 2023 16:15:38 +0000</pubDate>
      <link>https://dev.to/godszerg86/quick-and-easy-dbcontext-setup-in-net-51aa</link>
      <guid>https://dev.to/godszerg86/quick-and-easy-dbcontext-setup-in-net-51aa</guid>
      <description>&lt;p&gt;In .NET, a DbContext is a class that allows you to interact with a database using entity classes. In this article, we'll explore how to create a DbContext in .NET with code examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a DbContext&lt;/strong&gt;&lt;br&gt;
To create a &lt;code&gt;DbContext&lt;/code&gt;, we need to create a class that inherits from the &lt;code&gt;DbContext&lt;/code&gt; class. In this example, we'll create a &lt;code&gt;ProductDbContext&lt;/code&gt; class that represents a database of products:&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;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductDbContext&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;DbContext&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;ProductDbContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DbContextOptions&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ProductDbContext&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;base&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&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;public&lt;/span&gt; &lt;span class="n"&gt;DbSet&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Products&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code creates a &lt;code&gt;ProductDbContext&lt;/code&gt; class that inherits from the &lt;code&gt;DbContext&lt;/code&gt; class. The constructor accepts an &lt;code&gt;options&lt;/code&gt; parameter of type &lt;code&gt;DbContextOptions&amp;lt;ProductDbContext&amp;gt;&lt;/code&gt;, which allows us to configure the database connection. In this example, we're passing the options to the base constructor.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;ProductDbContext&lt;/code&gt; class also contains a &lt;code&gt;DbSet&amp;lt;Product&amp;gt;&lt;/code&gt; property that represents the entity set for products.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Register DbContext&lt;/strong&gt;&lt;br&gt;
In order to use the ProductDbContext class in your application, you need to register it with the dependency injection container. This can typically be done in your Startup class, like so:&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;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Startup&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;ConfigureServices&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IServiceCollection&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Register the DbContext&lt;/span&gt;
        &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddDbContext&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ProductDbContext&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
            &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseSqlite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Data Source=products.db"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="c1"&gt;// Other service registrations...&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;This code uses the &lt;code&gt;AddDbContext&lt;/code&gt; method to register the &lt;code&gt;ProductDbContext&lt;/code&gt; with the dependency injection container. It also configures the &lt;code&gt;DbContext&lt;/code&gt; to use SQLite as the database provider, the database file location as &lt;code&gt;products.db&lt;/code&gt; or you could use the connection string retrieved from the application configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Migrating the Database&lt;/strong&gt;&lt;br&gt;
Once we’ve created and configured the &lt;code&gt;DbContext&lt;/code&gt;, we need to create the database schema. To do this, we'll use Entity Framework Core migrations.&lt;/p&gt;

&lt;p&gt;First, install the Entity Framework Core tools using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet tool install --global dotnet-ef
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, add a migration using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet ef migrations add InitialCreate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates a new migration with the name &lt;code&gt;InitialCreate&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Finally, apply the migration to the database using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet ef database update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command applies the migration to the database and creates the schema.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using the DbContext&lt;/strong&gt;&lt;br&gt;
Now that we’ve created and configured the &lt;code&gt;DbContext&lt;/code&gt;, we can use it to interact with the database.&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;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductService&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;ProductDbContext&lt;/span&gt; &lt;span class="n"&gt;_dbContext&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;ProductService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ProductDbContext&lt;/span&gt; &lt;span class="n"&gt;dbContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_dbContext&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dbContext&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="p"&gt;&amp;lt;&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;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetProductsAsync&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;await&lt;/span&gt; &lt;span class="n"&gt;_dbContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Products&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ToListAsync&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetProductByIdAsync&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;id&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;await&lt;/span&gt; &lt;span class="n"&gt;_dbContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Products&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FindAsync&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="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;AddProductAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;product&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;_dbContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Products&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&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;_dbContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SaveChangesAsync&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;UpdateProductAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_dbContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Entry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;State&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;EntityState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Modified&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;_dbContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SaveChangesAsync&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;DeleteProductAsync&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;id&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;product&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;_dbContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Products&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FindAsync&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="n"&gt;_dbContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Products&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&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;_dbContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SaveChangesAsync&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;p&gt;In this example, we’ve defined a &lt;code&gt;ProductService&lt;/code&gt; class with a constructor that takes an instance of &lt;code&gt;ProductDbContext&lt;/code&gt; as a parameter. The &lt;code&gt;ProductDbContext&lt;/code&gt; instance is then stored in a private field called &lt;code&gt;_dbContext&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We’ve also defined a few methods for interacting with the products stored in the database. These methods use the &lt;code&gt;_dbContext&lt;/code&gt; instance to query, add, update, and delete &lt;code&gt;Product&lt;/code&gt; entities.&lt;/p&gt;

&lt;p&gt;With this setup, you can easily use the &lt;code&gt;ProductService&lt;/code&gt; class in your controllers or other services, and the &lt;code&gt;ProductDbContext&lt;/code&gt; instance will be automatically injected by the dependency injection container. For example, here's how you might use the &lt;code&gt;ProductService&lt;/code&gt; class in a controller:&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;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductsController&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Controller&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;ProductService&lt;/span&gt; &lt;span class="n"&gt;_productService&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;ProductsController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ProductService&lt;/span&gt; &lt;span class="n"&gt;productService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_productService&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;productService&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IActionResult&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Index&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;products&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;_productService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetProductsAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;View&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Other action methods...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this article, we’ve explored how to create a &lt;code&gt;DbContext&lt;/code&gt; in .NET with code examples. We've also seen how to configure the &lt;code&gt;DbContext&lt;/code&gt; and use it to interact with a database using entity classes. By following these examples, you should be able to create your own &lt;code&gt;DbContext&lt;/code&gt; and interact with a database in your .NET application.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>database</category>
      <category>dotnetcore</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>A brief introduction to MediatR in .NET</title>
      <dc:creator>Sergei Belialov</dc:creator>
      <pubDate>Sun, 21 May 2023 16:02:17 +0000</pubDate>
      <link>https://dev.to/godszerg86/a-brief-introduction-to-mediatr-in-net-2cmp</link>
      <guid>https://dev.to/godszerg86/a-brief-introduction-to-mediatr-in-net-2cmp</guid>
      <description>&lt;p&gt;MediatR is a popular open-source package for implementing the mediator pattern in .NET applications. It provides a simple way to separate the concerns of your application’s components by routing requests and responses through a mediator. In this article, we’ll explore how to install and use the MediatR package in .NET applications with code examples.&lt;/p&gt;

&lt;p&gt;You could support the project here:&lt;br&gt;
&lt;a href="https://github.com/jbogard/MediatR"&gt;https://github.com/jbogard/MediatR&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing MediatR Package&lt;/strong&gt;&lt;br&gt;
To install MediatR, we can use the NuGet Package Manager in Visual Studio or the .NET CLI. In this example, we’ll use the .NET CLI.&lt;/p&gt;

&lt;p&gt;First, navigate to the root directory of your .NET application in the command prompt. Then, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet add package MediatR
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install the latest version of the MediatR package in your .NET application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using MediatR Package&lt;/strong&gt;&lt;br&gt;
To use the MediatR package, we need to create a mediator and define the requests and handlers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a Mediator&lt;/strong&gt;&lt;br&gt;
To create a mediator, we need to register the MediatR services in the dependency injection container. In this example, we’ll use the default Microsoft dependency injection container.&lt;/p&gt;

&lt;p&gt;First, add the following line of code to the &lt;code&gt;ConfigureServices&lt;/code&gt;method in the &lt;code&gt;Startup.cs&lt;/code&gt; file:&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;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddMediatR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Startup&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will register the MediatR services in the dependency injection container and allow us to use the &lt;code&gt;IMediator&lt;/code&gt; interface to send requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defining Requests and Handlers&lt;/strong&gt;&lt;br&gt;
Requests in MediatR represent the input to the mediator. Handlers represent the logic for processing the requests. To define a request and its handler, we need to create two classes: a request class and a handler class.&lt;/p&gt;

&lt;p&gt;First, let’s create a request class. In this example, we’ll create a simple request to get a list of products:&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;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GetProductListQuery&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IRequest&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&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;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;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;p&gt;This request class inherits from the &lt;code&gt;IRequest&amp;lt;TResponse&amp;gt;&lt;/code&gt;interface, where &lt;code&gt;TResponse&lt;/code&gt; is the type of the response we expect from the handler.&lt;/p&gt;

&lt;p&gt;Next, let’s create a handler class to process the request. In this example, we’ll create a handler that returns a list of hardcoded products:&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;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GetProductListHandler&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IRequestHandler&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;GetProductListQuery&lt;/span&gt;&lt;span class="p"&gt;,&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;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;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="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&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;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;GetProductListQuery&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;CancellationToken&lt;/span&gt; &lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&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;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;productList&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;Product&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="nf"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;()&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;"Product 1"&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;Product&lt;/span&gt;&lt;span class="p"&gt;()&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;"Product 2"&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;Product&lt;/span&gt;&lt;span class="p"&gt;()&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;"Product 3"&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="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FromResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;productList&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;p&gt;This handler class implements the &lt;code&gt;IRequestHandler&amp;lt;TRequest, TResponse&amp;gt;&lt;/code&gt; interface, where &lt;code&gt;TRequest&lt;/code&gt; is the type of the request and &lt;code&gt;TResponse&lt;/code&gt; is the type of the response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sending Requests&lt;/strong&gt;&lt;br&gt;
To send a request to the mediator, we can use the &lt;code&gt;IMediator&lt;/code&gt; interface. In this example, we'll send a request to get a list of products and display the results in the console:&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;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductService&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;IMediator&lt;/span&gt; &lt;span class="n"&gt;mediator&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;ProductService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IMediator&lt;/span&gt; &lt;span class="n"&gt;mediator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mediator&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mediator&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;GetProductList&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;productList&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;mediator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Send&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;GetProductListQuery&lt;/span&gt;&lt;span class="p"&gt;());&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;product&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;productList&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="n"&gt;product&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="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;p&gt;This code creates a &lt;code&gt;ProductService&lt;/code&gt; class that accepts an &lt;code&gt;IMediator&lt;/code&gt; interface in the constructor. The &lt;code&gt;GetProductList&lt;/code&gt; sends a request to Mediatr with query params and accepts the results.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>mediatr</category>
      <category>dotnet</category>
      <category>dotnetcore</category>
    </item>
    <item>
      <title>Setting up a Python Environment</title>
      <dc:creator>Sergei Belialov</dc:creator>
      <pubDate>Sun, 21 May 2023 15:53:06 +0000</pubDate>
      <link>https://dev.to/godszerg86/setting-up-a-python-environment-39l0</link>
      <guid>https://dev.to/godszerg86/setting-up-a-python-environment-39l0</guid>
      <description>&lt;p&gt;Python is a versatile programming language used for various purposes, including data analysis, web development, and artificial intelligence. One of the most useful features of Python is the ability to create and use virtual environments. In this article, we’ll explore how to create and use a Python environment with examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Python environment?&lt;/strong&gt;&lt;br&gt;
A Python environment is a self-contained directory tree that contains a specific version of Python along with any required packages and dependencies. Python environments are useful for isolating different projects and avoiding conflicts between different versions of Python or installed packages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a Python environment&lt;/strong&gt;&lt;br&gt;
To create a Python environment, we can use the built-in &lt;code&gt;venv&lt;/code&gt; module. First, we need to navigate to the directory where we want to create the environment. Then, we can run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;python -m venv myenv
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new directory called myenv in the current directory, containing the necessary files for a new Python environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Activating the Python environment&lt;/strong&gt;&lt;br&gt;
To activate the Python environment, we need to run the activate script located in the &lt;code&gt;Scripts&lt;/code&gt; directory of the environment. On Windows, we can activate the environment with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;myenv\Scripts\activate.bat
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Linux or macOS, we can activate the environment with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source myenv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running the activate command, the terminal prompt will change to indicate that we are now in the virtual environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing packages in the Python environment&lt;/strong&gt;&lt;br&gt;
Once we have activated the Python environment, we can install packages using the pip command. For example, to install the &lt;code&gt;numpy&lt;/code&gt; package, we can run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install numpy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install the &lt;code&gt;numpy&lt;/code&gt; package in the &lt;code&gt;myenv&lt;/code&gt; environment. We can verify that the package is installed by running the following command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This will display a list of all installed packages in the current environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using the Python environment&lt;/strong&gt;&lt;br&gt;
Once we have installed the necessary packages in the Python environment, we can run Python scripts as usual. However, any packages or dependencies required by the script must be installed in the virtual environment.&lt;/p&gt;

&lt;p&gt;For example, suppose we have a script called &lt;code&gt;my_script.py&lt;/code&gt; that uses the &lt;code&gt;numpy&lt;/code&gt; package. We can run the script in the &lt;code&gt;myenv&lt;/code&gt; environment by first activating the environment and then running the script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source myenv/bin/activate
python my_script.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will run the script in the &lt;code&gt;myenv&lt;/code&gt; environment with the &lt;code&gt;numpy&lt;/code&gt; package installed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Python environments are a powerful tool for managing Python projects and dependencies. By creating a virtual environment for each project, we can avoid conflicts between different versions of Python or installed packages. In this article, we’ve explored how to create and use a Python environment with examples.&lt;/p&gt;

</description>
      <category>python</category>
      <category>development</category>
    </item>
    <item>
      <title>.NET 5.0 Blazor Web Assembly TODO List simple app</title>
      <dc:creator>Sergei Belialov</dc:creator>
      <pubDate>Sat, 12 Dec 2020 20:49:27 +0000</pubDate>
      <link>https://dev.to/godszerg86/net-5-0-blazor-web-assembly-todo-list-simple-app-331p</link>
      <guid>https://dev.to/godszerg86/net-5-0-blazor-web-assembly-todo-list-simple-app-331p</guid>
      <description>&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%2Fi%2F6h5euqjvcnzewvzs0e6c.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%2Fi%2F6h5euqjvcnzewvzs0e6c.png" alt="Blazor"&gt;&lt;/a&gt;&lt;br&gt;
Not so long ago Microsoft released .NET 5.0 and with this release, their front-end framework Blazor is getting even better support for Web Assembly hosting solution.&lt;/p&gt;

&lt;p&gt;In this article, we will try to write a TODO list SPA Web Assembly application using this framework. &lt;/p&gt;

&lt;p&gt;But before diving in let’s talk a little bit about what kind of benefits and downsides Web Assembly hosting solution carry with it.&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%2Fi%2Fhoi8eed3nubqsoxrefd6.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%2Fi%2Fhoi8eed3nubqsoxrefd6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;WebAssembly (often shortened to Wasm) is an open standard that defines a portable binary code format for executable programs, and a corresponding textual assembly language, as well as interfaces for facilitating interactions between such programs and their host environment. — Wikipedia&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To say simply it is an interface between compiled binary code (mostly C++ and Rust) and the environment where it executed — in our case web browser (JavaScript). All modern browsers support Wasm so you don’t need to worry about this part. &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;The Blazor WebAssembly hosting model offers several benefits:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;There’s no .NET server-side dependency. &lt;/li&gt;
&lt;li&gt;The app is fully functioning after downloaded to the client.&lt;/li&gt;
&lt;li&gt;Client resources and capabilities are fully leveraged.&lt;/li&gt;
&lt;li&gt;Work is offloaded from the server to the client.&lt;/li&gt;
&lt;li&gt;An ASP.NET Core web server isn’t required to host the app. Serverless deployment scenarios are possible (for example, serving the app from a CDN).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;However, there are some downsides to Blazor WebAssembly hosting:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The app is restricted to the capabilities of the browser.&lt;/li&gt;
&lt;li&gt;Capable client hardware and software (for example, WebAssembly support) are required.&lt;/li&gt;
&lt;li&gt;Download size is larger, and apps take longer to load.&lt;/li&gt;
&lt;li&gt;.NET runtime and tooling support are less mature. For example, limitations exist in .NET Standard support and debugging.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even with all downsides listed above, this solution looks really promising, so let say no more and start with our app!&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;But before building it we still need to install &lt;a href="https://dotnet.microsoft.com/download/dotnet/5.0" rel="noopener noreferrer"&gt;.NET 5.0.100 SDK&lt;/a&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;We are not going to write everything from scratch but instead, we start from Blazor WASM template by running the next command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new blazorwasm &lt;span class="nt"&gt;-o&lt;/span&gt; ToDoList
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fi%2Fhhrg07zwc40cficn1cfd.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%2Fi%2Fhhrg07zwc40cficn1cfd.png" alt="CLI message after running dotnet new command"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will generate a &lt;code&gt;ToDoList&lt;/code&gt; folder with the following project structure:&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%2Fi%2Fzx6utl0vs7yu0alonvqh.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%2Fi%2Fzx6utl0vs7yu0alonvqh.png" alt="Project structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s quickly go over some pieces of it, but if you bootstrapped Blazor projects before it will look very familiar to you.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pages&lt;/em&gt; folder – Contains &lt;code&gt;razor&lt;/code&gt; files for pages (routable), while &lt;em&gt;Shared&lt;/em&gt; holds all shared components used in Pages. &lt;em&gt;wwwroot&lt;/em&gt; is a public folder that contains all static data such as &lt;code&gt;css&lt;/code&gt; style files and &lt;code&gt;index.html&lt;/code&gt;. As you can see template shipped with Bootstrap components library. Still, one minor version behind (&lt;em&gt;on the date of writing this article Bootstrap has version 4.4 while template shipped with version 4.3.1, Microsoft should update templates faster, really…&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;Also, you may notice &lt;code&gt;open-iconinc&lt;/code&gt; which is an open-source sibling of &lt;a href="https://useiconic.com/" rel="noopener noreferrer"&gt;Iconic&lt;/a&gt;, the icons library. Kinda cool addition, but you always could switch to any other icon library, e.g. Bootstrap introduced their own icon library &lt;code&gt;bootstrap-icons&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Program.cs&lt;/em&gt; – is the main entry point of the whole app. for now it contains only a few basic lines. Services can be configured with the &lt;code&gt;ConfigureServices&lt;/code&gt; method on the host builder.&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;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddSingleton&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IMyDependency&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;MyDependency&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configuration can be supplied via the host &lt;code&gt;builder builder.Configuration&lt;/code&gt;. This is the main difference between Blazor Server and WebAssembly is the type of builder. As you could see for WASM application it is &lt;code&gt;WebAssemblyHostBuilder&lt;/code&gt;&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%2Fi%2Fk5rjfy5t7urc2l0s2vlw.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%2Fi%2Fk5rjfy5t7urc2l0s2vlw.png" alt="Program.cs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;RootComponents specifies the HTML tag ID where &lt;code&gt;App&lt;/code&gt; will be rendered, in this case &lt;code&gt;&amp;lt;app&amp;gt;…&amp;lt;/app&amp;gt;&lt;/code&gt; tag:&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%2Fi%2F9f5sxk03f5goduhuyit2.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%2Fi%2F9f5sxk03f5goduhuyit2.png" alt="index.html"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another interesting line here is &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag that points to &lt;code&gt;blazor.webassembly.js&lt;/code&gt; file. This JS file is responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Downloading the .NET runtime, the app, and the app’s dependencies.&lt;/li&gt;
&lt;li&gt;Initializing the runtime to run the app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;App.razor&lt;/em&gt; — The root component of the app that sets up client-side routing using the &lt;a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.routing.router?view=aspnetcore-5.0" rel="noopener noreferrer"&gt;Router&lt;/a&gt; component. The &lt;code&gt;Router&lt;/code&gt; component intercepts browser navigation and renders the page that matches the requested address.&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%2Fi%2Fvddmajrar2564j84mpv0.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%2Fi%2Fvddmajrar2564j84mpv0.png" alt="App.razor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This structure of components and their name styles reminds some other popular frameworks, such as VueJS.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;_Imports.razor&lt;/em&gt; — Includes common Razor directives to include in the app’s components (.razor), such as &lt;code&gt;@using&lt;/code&gt; directives for namespaces.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: You could run the app by pressing F5 in VS Code. Alternatively to run it from CLI use &lt;code&gt;dotnet run command&lt;/code&gt;. The app will be served at &lt;a href="http://localhost:5000" rel="noopener noreferrer"&gt;http://localhost:5000&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&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%2Fi%2F4o1u0olxs9sk7v34lv5n.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%2Fi%2F4o1u0olxs9sk7v34lv5n.png" alt="Served template app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But finally, let get to our app… For real this time!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's add a new page file named &lt;em&gt;Todo.razor&lt;/em&gt; to the app in the Pages folder. Notice &lt;code&gt;@page "/todo"&lt;/code&gt; binds this page to the new route.&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%2Fi%2Fdlfgbj5litncjydatde4.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%2Fi%2Fdlfgbj5litncjydatde4.png" alt="Todo.razor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And update the navigation bar inside Shared/NavMenu.razor:&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%2Fi%2F3o5446zw7hlzne5glpax.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%2Fi%2F3o5446zw7hlzne5glpax.png" alt="Shared/NavMenu."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's run the app with &lt;code&gt;dotnet watch run&lt;/code&gt; command and we should see our link to TODO list on the NavBar that will bring us to our new page.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE. &lt;code&gt;dotnet watch run&lt;/code&gt; will track the changes in the project files and refresh the browser. Similar to the live server. So you don't need to run it every time.&lt;/p&gt;
&lt;/blockquote&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%2Fi%2F0tbbsn02h3s5c13vzqqu.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%2Fi%2F0tbbsn02h3s5c13vzqqu.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok. The next step is to introduce &lt;code&gt;TodoItem&lt;/code&gt; model. Let's create a Model folder where we create TodoItem.cs file with next class:&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%2Fi%2Fakdinbu9s59ndsg54caz.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%2Fi%2Fakdinbu9s59ndsg54caz.png" alt="TodoOtem.cs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now when we have a model let use it inside Todo component. Go back to Pages/Todo.razor and add &lt;code&gt;@code&lt;/code&gt; section at the bottom of the file. This section holds all component business logic. You could think about this section as a nested Class within the Component.&lt;/p&gt;

&lt;p&gt;We will add a private field of &lt;code&gt;List&amp;lt;TodoItem&amp;gt;&lt;/code&gt; there:&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%2Fi%2F0nmu399p4ihkz4ng0ekw.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%2Fi%2F0nmu399p4ihkz4ng0ekw.png" alt="Pages/Todo.razor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's use this list to render TodoItems into UI. We are going to use an unordered list tag &lt;/p&gt;
&lt;ul&gt; for that. Just use C# &lt;code&gt;foreach&lt;/code&gt; to loop over the items.

&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%2Fi%2Fhftjvynps0dwfdc19q0o.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%2Fi%2Fhftjvynps0dwfdc19q0o.png" alt="Pages/Todo.razor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you may notice the &lt;code&gt;@&lt;/code&gt; symbol is used for UI logic code insertions. Similar to &lt;a href="https://mustache.github.io/" rel="noopener noreferrer"&gt;mustache&lt;/a&gt; syntax used in many popular Frontend frameworks.&lt;/p&gt;

&lt;p&gt;Alright looks like we missing an input to actually add data to &lt;code&gt;todos&lt;/code&gt; list. Go add it:&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%2Fi%2Fj28f03x94tu0ql5ix53g.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%2Fi%2Fj28f03x94tu0ql5ix53g.png" alt="Pages/Todo.razor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now our ToDo list looks way more attractive!&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%2Fi%2Fuyvq3uzdxze6c08ijdvg.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%2Fi%2Fuyvq3uzdxze6c08ijdvg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But it is not functional =( Let’s go fix it!. First we need to hook up &lt;code&gt;@onclick&lt;/code&gt; handler to the button. For that create a private method within &lt;code&gt;@code&lt;/code&gt; section and add &lt;code&gt;@onlcick&lt;/code&gt; attribute so it will look like this:&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%2Fi%2F9ppwlv4qix0hrthit5dx.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%2Fi%2F9ppwlv4qix0hrthit5dx.png" alt="Pages/Todo.razor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, but we missing a data binding between &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; tag for Todo Title and component class. Let's introduce another &lt;code&gt;string&lt;/code&gt; field and bind it to the &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; tag with &lt;code&gt;@bind&lt;/code&gt; attribute:&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%2Fi%2F84d1b8nfbi79j47ck59v.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%2Fi%2F84d1b8nfbi79j47ck59v.png" alt="Pages/Todo.razor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And some spicy logic to the &lt;code&gt;AddTodo&lt;/code&gt; method.&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%2Fi%2Fe9mqd3y4je478qv5zrw5.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%2Fi%2Fe9mqd3y4je478qv5zrw5.png" alt="Pages/Todo.razor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s test what we have so far. Because we using &lt;code&gt;dotnet watch run&lt;/code&gt; the app already reloaded in the browser and we could try adding some “todos”.&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%2Fi%2F4f0rorun84tnob564lno.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%2Fi%2F4f0rorun84tnob564lno.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It works! …. But looks boring… We will drop some extra functionality to gasp Blazor skills. Add UI tags and bind them to the model so we could edit “todos” title and status, but also count of undone tasks:&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%2Fi%2Fjfcuhblunxip4foijjt0.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%2Fi%2Fjfcuhblunxip4foijjt0.png" alt="Pages/Todo.razor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let see what we have this time?&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%2Fi%2F6vtm9jo842whw3p1lj84.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%2Fi%2F6vtm9jo842whw3p1lj84.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Delightful! Try changing values and see how reactivity works with model binding in Balzor. As you may notice when you change the title in the input, it reflects only when you unfocus the input element. This is the default behavior of Blazor &lt;code&gt;@bind&lt;/code&gt; attribute. It triggers on &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onchange" rel="noopener noreferrer"&gt;“onchange”&lt;/a&gt; event:&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%2Fi%2F6vtm9jo842whw3p1lj84.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%2Fi%2F6vtm9jo842whw3p1lj84.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But of course, this behavior could be changed.&lt;/p&gt;

&lt;p&gt;And that is it. We build or SPA ToDo list using Web Assembly with Blazor framework. To stop serving the app press &lt;code&gt;Ctrl + C.&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion.
&lt;/h3&gt;

&lt;p&gt;I really like how Blazor framework evolves and becomes more and more attractive, but like all other frameworks, it has its pros and cons. I like how easy it is to implement routing and model binding. Another benefit I like is a strong typed C# with and .NET 5.0 support that brings a lot of new features to the table.&lt;/p&gt;

&lt;p&gt;It really helps C# developers who like to develop some frontend but doesn’t really want to dive into JavaScript nightmare =).&lt;/p&gt;

&lt;p&gt;As for WebAssembly: yes it works fast but only when it's loaded. As you could see from Lighthouse report below, we build a pretty small app but it already has a size of around 9mb. So if your Web App is supposed to be more fast and lightweight from a user perspective, I will suggest you to avoid WASM.&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%2Fi%2F1ymbln0zf2826j6k6ju2.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%2Fi%2F1ymbln0zf2826j6k6ju2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But if you build an online tool (e.g. photo editor or smth heavyweight and static) that loads once and performance very very good and fast — then WASM is a solution for you!&lt;/p&gt;

&lt;p&gt;Source code could be found here: &lt;a href="https://github.com/godszerg86/BalozorWASM_ToDO" rel="noopener noreferrer"&gt;https://github.com/godszerg86/BalozorWASM_ToDO&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next article, we will try to host a .NET 5.0 WASM application using Docker image locally on your machine.&lt;/p&gt;


&lt;/ul&gt;

</description>
      <category>blazor</category>
      <category>csharp</category>
      <category>spa</category>
      <category>webassembly</category>
    </item>
  </channel>
</rss>
