<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>.net on chrisxfires blog</title><link>https://chriscodes.net/notes/_net/</link><description>Recent content in .net on chrisxfires blog</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Thu, 25 May 2023 00:00:00 -0600</lastBuildDate><atom:link href="https://chriscodes.net/notes/_net/index.xml" rel="self" type="application/rss+xml"/><item><title>.net application models</title><link>https://chriscodes.net/notes/_net/application-models/</link><pubDate>Wed, 10 Jan 2024 00:00:00 -0600</pubDate><guid>https://chriscodes.net/notes/_net/application-models/</guid><description>&lt;h1 id="overview">overview&lt;/h1>
&lt;p>This mindmap shows .NET application models and their relationships.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img src="./net-application-models.svg" alt="" />
&lt;/p>&lt;/p></description></item><item><title>generic host</title><link>https://chriscodes.net/notes/_net/generic-host/</link><pubDate>Sun, 26 Jun 2022 19:15:58 -0600</pubDate><guid>https://chriscodes.net/notes/_net/generic-host/</guid><description>&lt;h1 id="generic-host">generic host&lt;/h1>
&lt;p>A host is an object that encapsulates an app&amp;rsquo;s resources and lifetime functionality. This allows for control over the app&amp;rsquo;s startup and graceful shutdown.&lt;/p>
&lt;ul>
&lt;li>Examples: Dependency Injection, Logging, Configuration, &lt;code>IHostedService&lt;/code> implementations&lt;/li>
&lt;/ul>
&lt;p>Generic Host is represented by the &lt;code>HostBuilder&lt;/code> type.&lt;/p>
&lt;ul>
&lt;li>Namespace: &lt;code>Microsoft.Extensions.Hosting&lt;/code>&lt;/li>
&lt;li>Documentation:
&lt;a href="https://docs.microsoft.com/en-us/dotnet/core/extensions/generic-host" target="_blank" rel="noopener">https://docs.microsoft.com/en-us/dotnet/core/extensions/generic-host&lt;/a>&lt;/li>
&lt;/ul>
&lt;h1 id="process">process&lt;/h1>
&lt;p>When a host starts, it calls &lt;code>IHostedService.StartAsync&lt;/code> on each implementation of &lt;code>IHostedService&lt;/code> registered in the service container&amp;rsquo;s collection of hosted services. If the implementation is a worker service, it calls &lt;code>BackgroundService.ExecuteAsync&lt;/code>.&lt;/p></description></item><item><title>benchmarking</title><link>https://chriscodes.net/notes/_net/benchmarking/</link><pubDate>Sun, 16 Jan 2022 00:00:00 -0600</pubDate><guid>https://chriscodes.net/notes/_net/benchmarking/</guid><description>&lt;h1 id="benchmarking">benchmarking&lt;/h1>
&lt;p>&lt;code>dotnet add package BenchmarkDotNet&lt;/code>&lt;/p>
&lt;p>&lt;code>Program.cs&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cs" data-lang="cs">&lt;span class="line">&lt;span class="cl">&lt;span class="k">using&lt;/span> &lt;span class="nn">BenchmarkDotNet.Running&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span> &lt;span class="kd">static&lt;/span> &lt;span class="k">void&lt;/span> &lt;span class="n">Main&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">BenchmarkRunner&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">Run&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">SomeBenchmarks&lt;/span>&lt;span class="p">&amp;gt;();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>SomeBenchmarks.cs&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cs" data-lang="cs">&lt;span class="line">&lt;span class="cl">&lt;span class="k">using&lt;/span> &lt;span class="nn">BenchmarkDotNet.Attributes&lt;/span>&lt;span class="p">;&lt;/span> &lt;span class="c1">// [Benchmark]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span> &lt;span class="k">class&lt;/span> &lt;span class="nc">SomeBenchmarks&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="err">…&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kd">public&lt;/span> &lt;span class="n">SomeBenchmarks&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="err">…&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> [Benchmark(Baseline = true)]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kd">public&lt;/span> &lt;span class="kt">string&lt;/span> &lt;span class="n">SomeTest&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="err">…&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> [Benchmark]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kd">public&lt;/span> &lt;span class="kt">string&lt;/span> &lt;span class="n">SomeOtherTest&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="err">…&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Then:&lt;br>
&lt;code>dotnet run --configuration release&lt;/code>&lt;/p></description></item><item><title>index and range</title><link>https://chriscodes.net/notes/_net/index-and-range/</link><pubDate>Sun, 09 Jan 2022 19:17:18 -0700</pubDate><guid>https://chriscodes.net/notes/_net/index-and-range/</guid><description>&lt;h1 id="overviewhttpslearnmicrosoftcomen-usdotnetcsharptutorialsranges-indexes">
&lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/ranges-indexes" target="_blank" rel="noopener">overview&lt;/a>&lt;/h1>
&lt;p>Index and range operators can be used with any type that &lt;em>countable&lt;/em>. A type is countable if it has an &lt;code>int&lt;/code> property named &lt;code>Count&lt;/code> or &lt;code>Length&lt;/code> and a &lt;code>get&lt;/code> accessor.&lt;/p>
&lt;h1 id="indexhttpslearnmicrosoftcomen-usdotnetapisystemindexviewnet-90">
&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.index?view=net-9.0" target="_blank" rel="noopener">index&lt;/a>&lt;/h1>
&lt;p>&lt;code>System.Index&lt;/code> represents an index into a sequence.&lt;/p>
&lt;p>Normally, the index is an integer passed to the indexer of an array:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cs" data-lang="cs">&lt;span class="line">&lt;span class="cl">&lt;span class="kt">int&lt;/span> &lt;span class="n">index&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="m">3&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">Person&lt;/span> &lt;span class="n">p&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">people&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">index&lt;/span>&lt;span class="p">];&lt;/span> &lt;span class="c1">// The fourth Person in the array.&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The &lt;code>Index&lt;/code> value type can identify position.&lt;/p>
&lt;h2 id="creating">creating&lt;/h2>
&lt;p>This index counts from the start:&lt;/p></description></item></channel></rss>