<?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 Yunier&#39;s Wiki</title>
    <link>http://localhost:1313/tags/.net/</link>
    <description>Recent content in .NET on Yunier&#39;s Wiki</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Thu, 18 May 2023 00:00:00 +0000</lastBuildDate>
    <atom:link href="http://localhost:1313/tags/.net/rss" rel="self" type="application/rss+xml" />
    <item>
      <title>Use Custom OpenAPI Specification File In .NET</title>
      <link>http://localhost:1313/post/2023/use-custom-openapi-specification-file-in-.net/</link>
      <pubDate>Thu, 18 May 2023 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2023/use-custom-openapi-specification-file-in-.net/</guid>
      <description>&lt;p&gt;.NET has the ability to auto-generated &lt;a href=&#34;https://swagger.io/specification/&#34;&gt;OpenAPI specifications&lt;/a&gt; based on your code. You can use different decorators on your code like &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.producesresponsetypeattribute?view=aspnetcore-7.0&#34;&gt;ProducesResponseTypeAttribute&lt;/a&gt; or &lt;a href=&#34;https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.consumesattribute?view=aspnetcore-7.0&#34;&gt;ConsumesAttribute&lt;/a&gt; to produce more descriptive response details for web API help pages generated by tools like Swagger.&lt;/p&gt;&#xA;&lt;p&gt;What if you didn&amp;rsquo;t want to use the autogenerated spec, what if you instead wanted to expose an already written spec, perhaps because you follow an &lt;a href=&#34;https://blog.postman.com/what-is-api-first-design/&#34;&gt;API-first&lt;/a&gt; approach to building an API instead of a Code-First approach. How would you expose that OpenAPI file?&lt;/p&gt;</description>
    </item>
    <item>
      <title>Using AutoFixture</title>
      <link>http://localhost:1313/post/2023/using-autofixture/</link>
      <pubDate>Mon, 02 Jan 2023 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2023/using-autofixture/</guid>
      <description>&lt;p&gt;I enjoy writing unit tests and any tools that make writing tests easier are appreciated. For the last year, I have incorporated &lt;a href=&#34;https://github.com/AutoFixture/AutoFixture/&#34;&gt;AutoFixture&lt;/a&gt; into all of my unit tests. I have found AutoFixture to be an excellent tool, it changed the way I approach the &amp;ldquo;Arrange&amp;rdquo; phase.&lt;/p&gt;&#xA;&lt;p&gt;Previously, my arrange phase involved manually assigning values to properties, in a small class that is referenced by a few tests, you may tolerate manually assigning values. Once you start to deal with a class that has many properties such as nested properties as shown on the &amp;ldquo;Employee&amp;rdquo; class below, things get out of hand.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Code Coverage In .NET</title>
      <link>http://localhost:1313/post/2022/code-coverage/</link>
      <pubDate>Tue, 15 Nov 2022 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2022/code-coverage/</guid>
      <description>&lt;p&gt;If you are writing unit tests in .NET, you may eventually find the need to generate code coverage reports to show how much coverage your project has. The best tool for code coverage reports in my experience has been &lt;a href=&#34;https://github.com/coverlet-coverage/coverlet&#34;&gt;coverlet&lt;/a&gt; because it supports both .NET Framework and .NET Core.&lt;/p&gt;&#xA;&lt;h3 id=&#34;nunit&#34;&gt;NUnit&lt;/h3&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://nunit.org/&#34;&gt;NUnit&lt;/a&gt;, the tried and tested framework originally being a port of &lt;a href=&#34;https://junit.org/junit5/&#34;&gt;JUnit&lt;/a&gt;. A powerful tool that when combined with &lt;a href=&#34;https://www.nuget.org/packages/coverlet.console&#34;&gt;coverlet console&lt;/a&gt; can be used to generate code coverage reports. To demonstrate, I will create an NUnit test project targeting .NET Framework 4.8 along with a Class Library type project also targeting .NET Framework 4.8&lt;/p&gt;</description>
    </item>
    <item>
      <title>Authorization Code From Terminal</title>
      <link>http://localhost:1313/post/2022/authorization-code-from-terminal/</link>
      <pubDate>Sun, 05 Jun 2022 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2022/authorization-code-from-terminal/</guid>
      <description>&lt;p&gt;I was recently presented with a unique challenge at work. I needed to create a script that clones repositories from Bitbucket. The problem is that as of June 2022, Bitbucket only supports managing repositories using OAuth via two grant types, the authorization code grant &amp;amp; the implicit grant.&lt;/p&gt;&#xA;&lt;p&gt;I won&amp;rsquo;t get into the details here but the implicit grant is no longer recommended and is in fact discouraged from ever being used. Regardless of which flow I use I will end up facing the same problem, the browser. In both the implicit and authorization grant, user interaction (3-legged OAuth) is required, the end-user must provide their credentials in order to properly authenticate, in some cases this may even include multifactor authentication.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Shortening URLs</title>
      <link>http://localhost:1313/post/2022/shortening-urls/</link>
      <pubDate>Mon, 25 Apr 2022 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2022/shortening-urls/</guid>
      <description>&lt;p&gt;I was recently talking to another developer about the importance of never exposing internal identifiers to the outside world. A well-known example of this is using an auto-incrementing identity field in SQL and exposing that field through an API. A client can look at the highest number to tell how many records exist, in an ordering system this is far from ideal. Now everyone will know how many orders you have created. I recommend watching &lt;a href=&#34;https://youtu.be/FRsRoaubPiY?t=2363&#34;&gt;The Internet of Pwned Things&lt;/a&gt; by &lt;a href=&#34;https://twitter.com/troyhunt&#34;&gt;Troy Hunt&lt;/a&gt; for a real-world example.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Extracting Values From Types</title>
      <link>http://localhost:1313/post/2022/extracting-values-from-types/</link>
      <pubDate>Sun, 10 Apr 2022 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2022/extracting-values-from-types/</guid>
      <description>&lt;p&gt;Learned a cool &lt;a href=&#34;https://twitter.com/buhakmeh/status/1308089098306039814/photo/1&#34;&gt;little trick&lt;/a&gt; a while back from &lt;a href=&#34;https://twitter.com/buhakmeh&#34;&gt;Khalid&lt;/a&gt;. As a developer, you will often run into scenarios that require you to get a subset of all fields from a model. There are many ways to achieve this task, returning the type and then grabbing each property, for example, take the following User type.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;11&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;12&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;13&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;14&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f&#34;&gt;15&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-C#&#34; data-lang=&#34;C#&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;User&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; User(&lt;span style=&#34;color:#66d9ef&#34;&gt;string&lt;/span&gt; name, DateTime dob)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; random = &lt;span style=&#34;color:#66d9ef&#34;&gt;new&lt;/span&gt; Random();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Id = random.Next();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Name = name;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        DateOfBirth = dob;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;int&lt;/span&gt; Id { &lt;span style=&#34;color:#66d9ef&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;set&lt;/span&gt;; }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;string&lt;/span&gt; Name {&lt;span style=&#34;color:#66d9ef&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;set&lt;/span&gt;; }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; DateTime DateOfBirth { &lt;span style=&#34;color:#66d9ef&#34;&gt;get&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;set&lt;/span&gt;; }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;If you want to obtain the name and id property you can take the following approach.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Preventing Invalid Assembly Dependencies</title>
      <link>http://localhost:1313/post/2022/preventing-invalid-assembly-dependencies/</link>
      <pubDate>Sat, 12 Mar 2022 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2022/preventing-invalid-assembly-dependencies/</guid>
      <description>&lt;p&gt;.NET makes it super simple to update the dependencies of a project. If you are following a solution structure like &lt;a href=&#34;https://github.com/ardalis/CleanArchitecture#design-decisions-and-dependencies&#34;&gt;Clean Architecture&lt;/a&gt; where the &lt;a href=&#34;https://github.com/ardalis/CleanArchitecture#the-web-project&#34;&gt;Web project&lt;/a&gt; should not be referenced by the &lt;a href=&#34;https://github.com/ardalis/CleanArchitecture#the-core-project&#34;&gt;Core project&lt;/a&gt; or you have created your own solution structure that requires certain projects do not reference another project then you might need a way to avoid having developers incorrectly adding dependencies.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img loading=&#34;lazy&#34; src=&#34;http://localhost:1313/post/2022/preventing-invalid-assembly-dependencies/clean-architecture-projet-dependencies.png&#34; alt=&#34;clean architecture project dependencies&#34;  /&gt;&#xD;&#xA;&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The diagram above gives a high-level view of all project dependencies in a Clean Architecture solution. Built with &lt;a href=&#34;https://excalidraw.com/&#34;&gt;Excalidraw&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>The Order Of Interfaces Impacts Performace</title>
      <link>http://localhost:1313/post/2021/the-order-of-interfaces-impacts-performance/</link>
      <pubDate>Sat, 28 Aug 2021 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2021/the-order-of-interfaces-impacts-performance/</guid>
      <description>&lt;p&gt;I was looking through some of my bookmarked Github issues when I rediscovered issue &lt;a href=&#34;https://github.com/dotnet/runtime/pull/32488&#34;&gt;#32488&lt;/a&gt;, in that issue a &lt;a href=&#34;https://github.com/dotnet/runtime/pull/32488#discussion_r380818002&#34;&gt;comment&lt;/a&gt; was made that caught my attention. The comment stated that in .NET the order of interfaces impacts performance. This is because in the &lt;a href=&#34;https://docs.microsoft.com/en-us/dotnet/standard/clr&#34;&gt;.NET CLR&lt;/a&gt; all class definitions have a collection of methods and interface definitions. Casting is a linear search that walks the interface definition. If you are constantly casting to an Interface located at the end then the CLR must do a longer walk.&lt;/p&gt;</description>
    </item>
    <item>
      <title>The Problem With AcquireRequestState</title>
      <link>http://localhost:1313/post/2020/the-problem-with-acquirerequeststate/</link>
      <pubDate>Thu, 03 Sep 2020 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2020/the-problem-with-acquirerequeststate/</guid>
      <description>&lt;p&gt;In my second post, I wanted to cover AcquireRequestState. In my four years as a developer I have encountered issues with AcquireRequestState twice. So, what in the world is AcquireRequestState.&lt;/p&gt;&#xA;&lt;p&gt;AcquireRequestState is part of the ASP.NET &lt;a href=&#34;https://docs.microsoft.com/en-us/previous-versions/aspnet/bb470252(v=vs.100)&#34;&gt;Life Cycle&lt;/a&gt;, this is an event raised by the &lt;a href=&#34;https://docs.microsoft.com/en-us/dotnet/api/system.web.httpapplication?redirectedfrom=MSDN&amp;view=netframework-4.8&#34;&gt;HttpApplication&lt;/a&gt;, it keeps session state in sync. Though I suspect that most developers are familiar with this event for being a major performance pain in their .NET Framework application, as documented &lt;a href=&#34;https://stackoverflow.com/questions/30066925/long-delays-in-acquirerequeststate&#34;&gt;here&lt;/a&gt;, &lt;a href=&#34;https://discuss.newrelic.com/t/acquirerequeststate-is-delaying-response-times-web-api/38229&#34;&gt;here&lt;/a&gt;, &lt;a href=&#34;https://stackoverflow.com/questions/3629709/i-just-discovered-why-all-asp-net-websites-are-slow-and-i-am-trying-to-work-out&#34;&gt;here&lt;/a&gt;, &lt;a href=&#34;https://stackoverflow.com/questions/8349033/storing-anything-in-asp-net-session-causes-500ms-delays&#34;&gt;here&lt;/a&gt; and &lt;a href=&#34;https://stackoverflow.com/questions/35133150/newrelic-async-http-handler-and-acquirerequeststate&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Configure Serilog Sub-Loggers Using XML App Settings</title>
      <link>http://localhost:1313/post/2020/configure-serilog-sub-logger-from-appsettings/</link>
      <pubDate>Mon, 31 Aug 2020 00:00:00 +0000</pubDate>
      <guid>http://localhost:1313/post/2020/configure-serilog-sub-logger-from-appsettings/</guid>
      <description>&lt;p&gt;Serilog has a neat feature that allows you to configure sub-loggers. With this feature you can essentially have log specific instances running on your application.&lt;/p&gt;&#xA;&lt;p&gt;I recently had to configure a .NET Framework application to use two different sub-loggers and while I was able find many examples online on how to configure sub-loggers through AppSettings.json, I did not find any examples on how to configure them through AppSettings.config/App.config so I wanted to document that process on this post.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
