<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Kuba Matjanowski Blog RSS Feed]]></title><description><![CDATA[Kuba Matjanowski portfolio site]]></description><link>http://github.com/dylang/node-rss</link><generator>GatsbyJS</generator><lastBuildDate>Sat, 28 Nov 2026 19:27:57 GMT</lastBuildDate><item><title><![CDATA[Blue/Green Deployments in Azure Container Apps: A Practical Guide]]></title><description><![CDATA[Hey there! 👋 Let's talk about something that's been making my deployments much less stressful lately - blue/green deployments in Azure…]]></description><link>https://blog.matjanowski.pl/2025/01/26/blue-green-deployments-in-azure-container-apps/</link><guid isPermaLink="false">https://blog.matjanowski.pl/2025/01/26/blue-green-deployments-in-azure-container-apps/</guid><pubDate>Sun, 26 Jan 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Hey there! 👋 Let&apos;s talk about something that&apos;s been making my deployments much less stressful lately - blue/green deployments in Azure Container Apps. You know that feeling when you&apos;re about to deploy to production and your heart starts racing? Yeah, we&apos;ve all been there. But what if I told you there&apos;s a way to make it feel more like a smooth sail rather than walking on a tightrope?&lt;/p&gt;
&lt;h2&gt;Let&apos;s See It in Action First!&lt;/h2&gt;
&lt;p&gt;Before I dive into the nitty-gritty details, check out this visualization of our production deployment pipeline in GitHub Actions:&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/15eb4b44a6a308b5704cae7d72648587/990be/pipeline.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 11.39240506329114%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAACCAYAAABYBvyLAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAXklEQVR42nWNSw6AMAhEvf89TYyf1hYotC5GrEZXLgi84SUzzFvEOC1Yww4qBtH6jTWw3lnx+9p/LNqg9cCQRJCJwaIeGiIRkjNxgXhByLn/zWV2ji+3h93PDLXanRPmHZqxR+xerwAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Production Deployment Pipeline&quot;
        title=&quot;&quot;
        src=&quot;/static/15eb4b44a6a308b5704cae7d72648587/f058b/pipeline.png&quot;
        srcset=&quot;/static/15eb4b44a6a308b5704cae7d72648587/c26ae/pipeline.png 158w,
/static/15eb4b44a6a308b5704cae7d72648587/6bdcf/pipeline.png 315w,
/static/15eb4b44a6a308b5704cae7d72648587/f058b/pipeline.png 630w,
/static/15eb4b44a6a308b5704cae7d72648587/40601/pipeline.png 945w,
/static/15eb4b44a6a308b5704cae7d72648587/78612/pipeline.png 1260w,
/static/15eb4b44a6a308b5704cae7d72648587/990be/pipeline.png 2748w&quot;
        sizes=&quot;(max-width: 630px) 100vw, 630px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Pretty neat, right? This isn&apos;t just some fancy diagram - it&apos;s our actual production pipeline in action. It shows how we carefully orchestrate our deployment through several stages:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First, we prepare our images (web-api-rename-images)&lt;/li&gt;
&lt;li&gt;Then, we mark our current production version as &quot;blue&quot; (set-current-revision-blue)&lt;/li&gt;
&lt;li&gt;Next, we deploy our new version as &quot;green&quot; (add-new-revision)&lt;/li&gt;
&lt;li&gt;We start with a small rollout (rollout-10-percent)&lt;/li&gt;
&lt;li&gt;Finally, we go all in! (rollout-100-percent)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Each step has its purpose, and trust me, this measured approach has saved my bacon more than once!&lt;/p&gt;
&lt;h2&gt;What&apos;s This Blue/Green Thing Anyway?&lt;/h2&gt;
&lt;p&gt;Imagine you&apos;re a street performer (stick with me here!). Instead of just switching acts in front of your audience, you set up a second stage nearby. You prepare your new act on the second stage while the current show goes on. Once everything&apos;s ready, you smoothly guide your audience to the new stage. That&apos;s basically what blue/green deployment is!&lt;/p&gt;
&lt;p&gt;In more technical terms, you maintain two identical production environments. While one serves traffic (let&apos;s say the blue one), the other sits quietly on the side (that&apos;s our green one). When it&apos;s time to deploy, we get the new version ready in the quiet environment, and then - here&apos;s the cool part - we gradually shift traffic over to it.&lt;/p&gt;
&lt;h2&gt;How We Make It Happen&lt;/h2&gt;
&lt;p&gt;Let me show you how we implement this in real life. I&apos;ll break it down into the juicy parts that actually matter.&lt;/p&gt;
&lt;h3&gt;Setting Up Our New Version&lt;/h3&gt;
&lt;p&gt;First things first - we need to get our new version ready to rock:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Build and Push Docker image
  &lt;span class=&quot;token key atrule&quot;&gt;working-directory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; $&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; env.API_WORKDIR &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
    docker build . -t ${{ vars.ACR_LOGIN_SERVER }}/${{ env.APP_NAME }}-api:${PROD_TAG}
    docker push ${{ vars.ACR_LOGIN_SERVER }}/${{ env.APP_NAME }}-api:${PROD_TAG}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is just us packaging up our application into a nice, neat container and storing it in Azure Container Registry. Think of it as preparing your costume before the show!&lt;/p&gt;
&lt;h3&gt;The Clever Part: Canary Deployments&lt;/h3&gt;
&lt;p&gt;Now, here&apos;s where it gets interesting. Instead of just throwing our new version out there and hoping for the best, we use something called a canary deployment. Why canary? Well, back in the day, miners used to take canaries into coal mines - if the canary stopped singing, they knew there was trouble with the air. We&apos;re doing something similar with our code!&lt;/p&gt;
&lt;p&gt;We start by sending just 10% of our users to the new version:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;az containerapp ingress traffic set \
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;name $&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; env.CONTAINER_APP_NAME &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; \
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;label&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;weight blue=90 green=10&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This means if something goes wrong, we&apos;ve only affected a small portion of our users. Pretty considerate of us, right? During this time, we&apos;re watching everything like a hawk:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Are there any errors popping up?&lt;/li&gt;
&lt;li&gt;Is the application running as fast as it should?&lt;/li&gt;
&lt;li&gt;Are users still able to do what they need to do?&lt;/li&gt;
&lt;li&gt;Is our database behaving itself?&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Safety First: Deployment Gates&lt;/h3&gt;
&lt;p&gt;Here&apos;s a pro tip I learned the hard way: never let your pipeline run wild without some safety checks! We use deployment gates, which are like responsible friends who won&apos;t let you send that late-night message to your ex without reading it twice.&lt;/p&gt;
&lt;p&gt;One way to add these safety checks is through GitHub&apos;s environment protection rules. These allow you to require approvals before deployments can proceed:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;jobs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;rollout-100-percent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 
      &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; production
      &lt;span class=&quot;token key atrule&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; https&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;//your&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;app&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;url.com&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, a quick heads-up about this feature: while it&apos;s available for public repositories on all GitHub plans, for private repositories you&apos;ll need GitHub Pro, GitHub Team, or GitHub Enterprise. It&apos;s one of those &quot;premium&quot; features that, while nice to have, isn&apos;t essential for implementing blue/green deployments.&lt;/p&gt;
&lt;p&gt;But don&apos;t worry if you&apos;re not on those plans! There are other ways to implement safety checks. My personal favorite is using automated metric-based gates:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Check deployment metrics
  &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
    error_rate=$(az monitor metrics list \
      --resource ${{ env.CONTAINER_APP_NAME }} \
      --metric &quot;http5xx&quot;)&lt;/span&gt;
    
    if &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; &quot;$error_rate&quot; &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;gt &quot;0.1&quot; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;; then
      echo &quot;Whoa there&lt;span class=&quot;token tag&quot;&gt;!&lt;/span&gt; Error rate is too high&lt;span class=&quot;token tag&quot;&gt;!&lt;/span&gt;&quot;
      exit 1
    fi&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;The Grand Finale&lt;/h2&gt;
&lt;p&gt;Once everything looks good, we go all in:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;az containerapp ingress traffic set \
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;name $&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; env.CONTAINER_APP_NAME &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; \
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;label&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;weight blue=0 green=100&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And just like that, we&apos;ve successfully deployed our new version! But here&apos;s the best part - if anything goes wrong, we can quickly switch back to our blue environment. It&apos;s like having a time machine for your deployments!&lt;/p&gt;
&lt;h2&gt;Wrapping Up&lt;/h2&gt;
&lt;p&gt;Blue/green deployments in Azure Container Apps have been a game-changer for our team. Sure, it might seem like a bit more work upfront, but trust me, it&apos;s worth it. The peace of mind you get from knowing you can quickly rollback if needed is priceless.&lt;/p&gt;
&lt;p&gt;Remember, the goal here isn&apos;t just to deploy faster - it&apos;s to deploy more safely and confidently. And isn&apos;t that what we all want? Sweet dreams of zero-downtime deployments, my friends!&lt;/p&gt;
&lt;p&gt;Got questions? Found a cool way to improve this setup? I&apos;d love to hear from you! Drop a comment below or hit me up on Twitter. After all, we&apos;re all in this together, trying to make our deployments less scary and more reliable! 🚀&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Managing options and secrets in .NET Core and Docker]]></title><description><![CDATA[.NET Core comes with tens of good patterns and helpers which are supposed to help developers to create high quality code which is easy to…]]></description><link>https://blog.matjanowski.pl/2017/11/18/managing-options-and-secrets-in-net-core-and-docker/</link><guid isPermaLink="false">https://blog.matjanowski.pl/2017/11/18/managing-options-and-secrets-in-net-core-and-docker/</guid><pubDate>Sat, 18 Nov 2017 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;.NET Core comes with tens of good patterns and helpers which are supposed to help developers to create high quality code which is easy to maintain and fast to develop. Numerous tools help us to be more productive but also encourage us to be responsible for our code and developer assets.&lt;/p&gt;
&lt;p&gt;I’m going to show you how do I solve the problem of managing configuration in .NET Core, including multiple environments, secrets and Docker.&lt;/p&gt;
&lt;h2&gt;App Settings&lt;/h2&gt;
&lt;p&gt;First of all: where do we use configuration? Of course there is no simple answer for that and it always depends, but my strategy for this is following. Each time when you use some constant (regardless of having them in the constant field or just used value) ask yourself: “Might this value ever change?”. If the answer is “yes” or “maybe” you should put it into a configuration value.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;String.Empty&lt;/code&gt; – constant&lt;/li&gt;
&lt;li&gt;Number of minutes to expire cache – configuration value&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In old .NET Framework we had a class called &lt;code class=&quot;language-text&quot;&gt;ConfigurationManager&lt;/code&gt; which had two main drawbacks: it used XML (the part of App.config file) and it was a static class, so you couldn’t easily mock it or inject. What we have now in .NET Core are Options and an interface &lt;code class=&quot;language-text&quot;&gt;IConfigurationRoot&lt;/code&gt; which is a root of all configuration nodes. It means that now we don’t have a flat configuration file with tens or hundreds of floating configuration keys, but a structured and grouped application settings.&lt;/p&gt;
&lt;p&gt;To start working with this, you need to use &lt;code class=&quot;language-text&quot;&gt;ConfigurationBuilder&lt;/code&gt;. If you use ASP.NET Core it’s worth to build it in the &lt;code class=&quot;language-text&quot;&gt;Statup&lt;/code&gt; constructor, where you have access to &lt;code class=&quot;language-text&quot;&gt;IHostingEnvironment&lt;/code&gt; and you can choose used configuration file is going to be used.&lt;/p&gt;
&lt;p&gt;The construction can look like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Startup&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IHostingEnvironment&lt;/span&gt; env&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt;&lt;/span&gt; builder &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;ConfigurationBuilder&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;SetBasePath&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;env&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ContentRootPath&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;AddJsonFile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;appsettings.json&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token named-parameter punctuation&quot;&gt;reloadOnChange&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;AddJsonFile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;$&quot;appsettings.&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token expression language-csharp&quot;&gt;env&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;EnvironmentName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;.json&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token named-parameter punctuation&quot;&gt;optional&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;AddEnvironmentVariables&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    Configuration &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; builder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;IConfigurationRoot&lt;/span&gt; Configuration &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;SetBasePath&lt;/code&gt; tells where should all files are placed. In the typical scenario it’s the current root path.&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;AddJsonFile&lt;/code&gt; adds a particular file to our configuration. It’s important to use the one that corresponds to the current environment. We should treat&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;appsettings.json&lt;/code&gt; as a common configuration file, while the one with environment name suffix is a environment specific one. Basically, one uses two basic environments: Development and Production (files: &lt;code class=&quot;language-text&quot;&gt;appsettings.Development.json&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;appsettings.Production.json&lt;/code&gt;), but for real business projects you should include Staging and Testing environments with setting values defined according to your needs. There are also two optional parameters: when you set  &lt;code class=&quot;language-text&quot;&gt;optional&lt;/code&gt; to &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt;, it means that you will not get any exception when the file does not exist and &lt;code class=&quot;language-text&quot;&gt;reloadOnChange&lt;/code&gt; will just update the configuration tree in memory every time when you edit a file.&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;AddEnvironmentVariables()&lt;/code&gt; adds a support for locally configured environment variables, so when you set up a variable you can use it in the app. &lt;code class=&quot;language-text&quot;&gt;auth:token&lt;/code&gt; crates a &lt;code class=&quot;language-text&quot;&gt;token&lt;/code&gt; value in &lt;code class=&quot;language-text&quot;&gt;auth&lt;/code&gt; section.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There is a bunch of providers available on NuGet which supports other files or sources. There is no problem to use XML or ini files. Just search for &lt;code class=&quot;language-text&quot;&gt;Microsoft.Extensions.Configuration&lt;/code&gt; and find something for you. There is something else worth to mention which is &lt;code class=&quot;language-text&quot;&gt;Microsoft.Extensions.Configuration.AzureKeyVault&lt;/code&gt;. It provides a service for storing secret data in secure storage on Azure – I’ll go deeper into this concept on another post.&lt;/p&gt;
&lt;p&gt;Let’s add just two simple files with some service configuration files:
&lt;code class=&quot;language-text&quot;&gt;appsettings.json&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;json&quot;&gt;&lt;pre class=&quot;language-json&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;&quot;RedisCache&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;Url&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;redis.matjanowski.pl&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;ExpireTimeInSeconds&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3600&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;and &lt;code class=&quot;language-text&quot;&gt;appsettings.Development.json&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;json&quot;&gt;&lt;pre class=&quot;language-json&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;RedisCache&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token property&quot;&gt;&quot;Url&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;localhost:6379&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;token property&quot;&gt;&quot;ExpireTimeInSeconds&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;15&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you see, &lt;code class=&quot;language-text&quot;&gt;RedisCache&lt;/code&gt; node is well-defined and we can type a simple class which describes it:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;CacheConfig&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; Url &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; ExpireTimeInSeconds &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;So far so good! We are ready to use our configuration in the app. The ASP.NET Core gives an ability to register it in the container so we can inject it into other classes. When we use default ASP.NET Core Dependency Container we should configure services in &lt;code class=&quot;language-text&quot;&gt;ConfigureServices&lt;/code&gt; method in &lt;code class=&quot;language-text&quot;&gt;Startup&lt;/code&gt; class:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;ConfigureServices&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IServiceCollection&lt;/span&gt; services&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    services&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token generic-method&quot;&gt;&lt;span class=&quot;token function&quot;&gt;Configure&lt;/span&gt;&lt;span class=&quot;token generic class-name&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;CacheConfig&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Configuration&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;GetSection&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;RedisCache&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    services&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;AddMvc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then you can inject the confiruration into your classes wrapped in a &lt;code class=&quot;language-text&quot;&gt;IOptions&amp;lt;T&gt;&lt;/code&gt; class where &lt;code class=&quot;language-text&quot;&gt;T&lt;/code&gt; is the config class defined a while ago:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;HomeController&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token type-list&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;Controller&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;CacheConfig&lt;/span&gt; _config&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;HomeController&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IOptions&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;CacheConfig&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; config&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        _config &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;IActionResult&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;About&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        ViewData&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Time&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; _config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ExpireTimeInSeconds&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        ViewData&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Url&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; _config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Url&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;View&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Depending on the running environment I get different results on my view:
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/593a492f7ddf84ebc6d079744901d088/2bef9/ProdVsDev.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 24.68354430379747%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAIAAADKYVtkAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAwklEQVR42l1PzQ6CMAzm/eQAnPSgRmXPLJi4lQECJnowwhjrmFWjQb+kTfP9JfU2my1jLN7FLGar5TIIgjAICVEU+b6/nvmL+WL+AZFvw3OHoSdllue54FwAVHVljEG0tOgYx/F25ABQliWAEIJfrhci8QOPAllGBmjb1jlHmpvgDkDVUso0Sc5NY62dql7fq67r3qO1dr/h4VSpl9gqpc1g/sKIZkDs67rbp316sEXpEL8yVjW9oZVSR66SdCiKafsD97z5J3OIx2wAAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Difference between environments&quot;
        title=&quot;&quot;
        src=&quot;/static/593a492f7ddf84ebc6d079744901d088/f058b/ProdVsDev.png&quot;
        srcset=&quot;/static/593a492f7ddf84ebc6d079744901d088/c26ae/ProdVsDev.png 158w,
/static/593a492f7ddf84ebc6d079744901d088/6bdcf/ProdVsDev.png 315w,
/static/593a492f7ddf84ebc6d079744901d088/f058b/ProdVsDev.png 630w,
/static/593a492f7ddf84ebc6d079744901d088/40601/ProdVsDev.png 945w,
/static/593a492f7ddf84ebc6d079744901d088/2bef9/ProdVsDev.png 1024w&quot;
        sizes=&quot;(max-width: 630px) 100vw, 630px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;Secrets&lt;/h2&gt;
&lt;p&gt;There is a temptation to use app settings to all kinds of variable config values, but there are some which should not be saved in the &lt;code class=&quot;language-text&quot;&gt;appsettings.json&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;DO NOT SAVE IN &lt;code class=&quot;language-text&quot;&gt;appsettings.json&lt;/code&gt; FOLLOWING SETTINGS:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;connection strings&lt;/li&gt;
&lt;li&gt;passwords&lt;/li&gt;
&lt;li&gt;password hashes&lt;/li&gt;
&lt;li&gt;API keys&lt;/li&gt;
&lt;li&gt;tokens&lt;/li&gt;
&lt;li&gt;“Peppers”&lt;/li&gt;
&lt;li&gt;cryptographic keys&lt;/li&gt;
&lt;li&gt;… and other values which are confidential&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Remember that those files are checked in your source code control system and you probably don’t want to share your production passwords with all repository users. What’s more, it might happen that some day your repository will be compromised or you simply go open source. I can bet, that there are tens of confidential data on GitHub or BitBucket public repositories. You don’t want to make this mistake.&lt;/p&gt;
&lt;p&gt;.NET Core comes to you with a solution. They developed sort of provider which apart of looking into &lt;code class=&quot;language-text&quot;&gt;appsettings.json&lt;/code&gt; uses values from some &lt;code class=&quot;language-text&quot;&gt;secret.json&lt;/code&gt; file which is saved on each developer’s machine locally in the special folder assigned to the project (the folder name is a GUID specific for a project).&lt;/p&gt;
&lt;p&gt;So to use them we will use VisualStudio 2017. We will need to install another NuGet package: &lt;code class=&quot;language-text&quot;&gt;Microsoft.Extensions.Configuration.UserSecrets&lt;/code&gt;. Next, let’s use IDE to generate secrets.json in a proper directory. Right-click on the project and choosing “Manage User Secrets” will do the thing.&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/9acd7547dcaae43a1a60b91747344e79/31198/UserSecrets.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 90.50632911392405%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAIAAADUsmlHAAAACXBIWXMAAA7DAAAOwwHHb6hkAAACYUlEQVR42n2TW2+bQBCF/RtaJTawywLLLgss1+W2YJI4dpo0VdREfepbHvseVVWl9rl/uwOp26RyIh2hEfY3czxzvOj0ehxP27bfnO26bshzBXXTdNVwsbn+NF7enVzdrd/dDrsbvbspT96r0+tE78J6o9YXC1VWZVlxHnAuGAs8j/k+9ym1k96vt1Rftfc/+i+/6vuf4efvxsevxu235c3Dmw8Pq+39glJfygSey+XKMMxHmaZlrY6No7fW8mjs+1qVvudSz2XQG0Q9Tj3BgwXGdpYVhDiWhZ4J2ZaFieNpPQghwA742gtqFgThwvdZHEtCyGplADPN3PNQQ9OyKOE7M/BUM5zEeaWaum6KvJAylXGCEIaZINNEtu1o3cNGAOB/Zj6B4WMA8qyY5zsIEYTsv4I3dTW1llJ6Hn1iYYZd14vjJJHTQMOwJpnWbB6bFsaYdJ3udZ8kaZpmQoTP4LSolKp117d12zQtdGE+8ymbzCNs22Rcj7rTWZaDwjDaD59hh/IgkiwIPZ9TFvg8gBceZSbCIDDe90PXdnBL0P+2MxGfFGrIilamfZYLbNOlwQyTmxY8I5s0SgWBOLyw8zA5r5vrYbzUw7ZqujDeK2rC+EyECoxM5KFT6SS9aPW26TZVXYsowkQS91FQZ8QV04754Tu7PIIAwW87XhrznpFhojkvNqXMwjYciL8El7GsVAXNIWFzPP5lSwQhpBT2xF6CIedzSPL5PDZEHVqgOdjgBOpD2dzDlMdJmitVQQsIGWQGnIOmfwVxICSvTYYzAAbXh5mO4wIAwXgMM6QKilfg39UUqR81vPowAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;User secrets in Visual Studio&quot;
        title=&quot;&quot;
        src=&quot;/static/9acd7547dcaae43a1a60b91747344e79/f058b/UserSecrets.png&quot;
        srcset=&quot;/static/9acd7547dcaae43a1a60b91747344e79/c26ae/UserSecrets.png 158w,
/static/9acd7547dcaae43a1a60b91747344e79/6bdcf/UserSecrets.png 315w,
/static/9acd7547dcaae43a1a60b91747344e79/f058b/UserSecrets.png 630w,
/static/9acd7547dcaae43a1a60b91747344e79/31198/UserSecrets.png 694w&quot;
        sizes=&quot;(max-width: 630px) 100vw, 630px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;
A JSON file will open, but nothing will be added into your project. It’s been created in one of the following folders (depending on your OS):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Windows: &lt;code class=&quot;language-text&quot;&gt;%APPDATA%\microsoft\UserSecrets\&amp;lt;userSecretsId&gt;\secrets.json&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Linux: &lt;code class=&quot;language-text&quot;&gt;~/.microsoft/usersecrets/&amp;lt;userSecretsId&gt;/secrets.json&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Mac: &lt;code class=&quot;language-text&quot;&gt;~/.microsoft/usersecrets/&amp;lt;userSecretsId&gt;/secrets.json&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;&amp;lt;userSecretsId&gt;&lt;/code&gt; is basically a GUID which can be checked in the &lt;code class=&quot;language-text&quot;&gt;.csproj&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;Let’s setup some configuration here:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;json&quot;&gt;&lt;pre class=&quot;language-json&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;RedisCache&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token property&quot;&gt;&quot;Key&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;THIS_IS_VERY_CONFIDENTIAL_STRING_USED_AS_PASSWORD&quot;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The last thing to use it is adding secrets support into our configuration. &lt;em&gt;We will do it only in Development environment, though, since it’s not recommended to use user’s secrets on the production&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt;&lt;/span&gt; builder &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;ConfigurationBuilder&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;SetBasePath&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;env&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ContentRootPath&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;AddJsonFile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;appsettings.json&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token named-parameter punctuation&quot;&gt;optional&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token named-parameter punctuation&quot;&gt;reloadOnChange&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;AddJsonFile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;$&quot;appsettings.&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token expression language-csharp&quot;&gt;env&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;EnvironmentName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;.json&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token named-parameter punctuation&quot;&gt;optional&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;AddEnvironmentVariables&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;env&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;IsDevelopment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    builder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token generic-method&quot;&gt;&lt;span class=&quot;token function&quot;&gt;AddUserSecrets&lt;/span&gt;&lt;span class=&quot;token generic class-name&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;Startup&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The class passed in the generic parameter is any one defined in the assembly which is a result of building project with &lt;code class=&quot;language-text&quot;&gt;UserSecretsId&lt;/code&gt; defined in it’s &lt;code class=&quot;language-text&quot;&gt;csproj&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;Now you can use it as a regular configuration, with this difference that it’s only visible on your machine. Each developer needs to create own &lt;code class=&quot;language-text&quot;&gt;secrets.json&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;IActionResult&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;About&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    ViewData&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Time&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; _config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ExpireTimeInSeconds&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    ViewData&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Url&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; _config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Url&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    ViewData&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Key&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; _config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Key&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// displaying it, is a terrible example :)&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;View&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Additionally some tweaks in the view and…. the result is:
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/17f0b1144f412ac8698ad8ffae110491/3c051/UserSecrets_result.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 26.58227848101266%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAIAAADKYVtkAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAsUlEQVR42o3PvQ6DIBAHcF7HDtouEj/6/lNlcUT5EC0k4AMUlJ40cWiX/objfyRHOFSW+N62VVXVdd00DRSMcZ7nxfVQFHDeIGRZdvmBCCGPruv7niRdQikdEpqc4Quy1io1AQbG0bl1Xd22bfEPMOymSY6MCSG11nAFkyGEV+K9/2SoZz5aH/Z9R9bZ5bnop4YvCMG1NpxzY4zgfKDDPC+QOWNKKSmP14UQsIXRJsb4BqCY50B/nbkDAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;User secrets result&quot;
        title=&quot;&quot;
        src=&quot;/static/17f0b1144f412ac8698ad8ffae110491/f058b/UserSecrets_result.png&quot;
        srcset=&quot;/static/17f0b1144f412ac8698ad8ffae110491/c26ae/UserSecrets_result.png 158w,
/static/17f0b1144f412ac8698ad8ffae110491/6bdcf/UserSecrets_result.png 315w,
/static/17f0b1144f412ac8698ad8ffae110491/f058b/UserSecrets_result.png 630w,
/static/17f0b1144f412ac8698ad8ffae110491/3c051/UserSecrets_result.png 760w&quot;
        sizes=&quot;(max-width: 630px) 100vw, 630px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;You can distribute secret values to developers in some safe way, but remember that those values are used only for development purposes.&lt;/p&gt;
&lt;h2&gt;Secrets in Docker&lt;/h2&gt;
&lt;p&gt;Once Microsoft went OpenSource and the hell got frozen, they also started to be open for many external tools like Docker. Microsoft started using Docker for internal projects but also added very good support for it in Visual Studio 2017. But if we run our app in a container, we are loosing an access to the &lt;code class=&quot;language-text&quot;&gt;secrets.json&lt;/code&gt; stored somewhere on the host machine. Let’s tackle this problem. I’m starting with adding Docker support via VS2017. Again, right-click → Add → Docker support. It’ll ask for a version of container and I’m choosing Linux. Next steps will depend of this decision.
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/63a1a5621b29d0ca26800f957b82caf8/f3c12/add_docker_support.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 83.54430379746836%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAARCAIAAABSJhvpAAAACXBIWXMAAA7DAAAOwwHHb6hkAAACUklEQVR42m1TS2/TQBjMb+DU2t73eteP9TtO/WiTqmk4gCgICSGOSHAq516QkDhwqPjTjJPWLRDrO6ysHc98M+OFUopzQSmhjw8hVHBaDdfN26/D5+/rb78vbu83t/ftl1/84w/x6efJu7sXN3fh5v0ijpPlsmWMe57v+8E8XkA9rlbr3fWbD93Vq7juVdYyt6Jpy7OVyDubNwvcszYKAvIcOYE9j5Fg7FZXm7XVSglupDBqPzgInkTJQuuwLKvAJ6enfzN7gWB0u+mG4dylLgzNP5MkbqGUrqrauSyyse+TeQCmhHfduL3a9l1vrT0CDggtq7qqmiRJfZ8GwdMQypardrd7OY7nxhwDM8acy6MoBhU8g/i9/j25H+RlOQ6jNRbbHQEnrlg2bd8P7fKsqZfGRGFoKYX52JxIqfSEmzF2ljCB06xs21VRVEVRwrnDAStAi40Sa2N4gSDRhX0dGFqALz6AIak762FJ1w1FXkA5YsMNDA5plvXDiL3wGqNDg6GMP4ChC1Qgr+tGCOlD7WPmUK64yJK0cHliIxYQQZmEihkMHxBVmkxJ7k0mhwGPJOymbm7Gi9ddf+nywUaDsb2JLrSJdBgfmNFQ7AaTwDaDGROSiVqby6Zdl3WlTS5kxoVjvJDKhGYCNzmeAr/FYdvHhhEYhrWVNUVZwTku1cm0sw2NJU+y9SQbBcTV58yHkqF/uCCFVFCoNAiBDveZT2AdOdSrqRusDf1zPRmXnEukgmDnbBH53JYJDHlp6owxnAm4jUgRJg4wHylOzP/9EjP4D94knO3jvA+tAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Add docker spport&quot;
        title=&quot;&quot;
        src=&quot;/static/63a1a5621b29d0ca26800f957b82caf8/f058b/add_docker_support.png&quot;
        srcset=&quot;/static/63a1a5621b29d0ca26800f957b82caf8/c26ae/add_docker_support.png 158w,
/static/63a1a5621b29d0ca26800f957b82caf8/6bdcf/add_docker_support.png 315w,
/static/63a1a5621b29d0ca26800f957b82caf8/f058b/add_docker_support.png 630w,
/static/63a1a5621b29d0ca26800f957b82caf8/f3c12/add_docker_support.png 764w&quot;
        sizes=&quot;(max-width: 630px) 100vw, 630px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Magic is happening now and we have new “project” available. If we have Docker deamon started, we can run the program. The first build might take a while to download all needed images. When the app starts you, your secret configuration value will be empty. Why it’s so? It’s because the app started in sandbox environment on Linux, so it cannot reach the secret value from your &lt;code class=&quot;language-text&quot;&gt;usersecrets&lt;/code&gt; directory.&lt;/p&gt;
&lt;p&gt;What we need to do is mounting a volume with the &lt;code class=&quot;language-text&quot;&gt;secret.json&lt;/code&gt;. Let’s open &lt;code class=&quot;language-text&quot;&gt;docker-compose.override.yml&lt;/code&gt; and change from this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;3&apos;&lt;/span&gt;

&lt;span class=&quot;token key atrule&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;managingconfigurationnetcore&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; ASPNETCORE_ENVIRONMENT=Development
    &lt;span class=&quot;token key atrule&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;80&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;to this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;3&apos;&lt;/span&gt;

&lt;span class=&quot;token key atrule&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;managingconfigurationnetcore&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; ASPNETCORE_ENVIRONMENT=Development
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; USER_SECRETS_ID=836b9b8b&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;fd89&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;4aff&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;9286&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;809bda60998f
    &lt;span class=&quot;token key atrule&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;80&quot;&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;volumes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; $APPDATA/Microsoft/UserSecrets/$USER_SECRETS_ID&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;/root/.microsoft/usersecrets/$USER_SECRETS_ID
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; $HOME/.microsoft/usersecrets/$USER_SECRETS_ID&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;/root/.microsoft/usersecrets/$USER_SECRETS_ID&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;What I’ve added are essentially 4 lines. I’ve defined an environment variable with &lt;code class=&quot;language-text&quot;&gt;UserSecretsId&lt;/code&gt; created in the &lt;code class=&quot;language-text&quot;&gt;.csproj&lt;/code&gt; (it’s inside the &lt;code class=&quot;language-text&quot;&gt;UserSecretsId&lt;/code&gt; tag) and I’ve defined &lt;code class=&quot;language-text&quot;&gt;volumes:&lt;/code&gt; section with two rules. First of them covers a Windows hosting machine and the second one covers Linux and Mac. I didn’t test it on Linux or Mac but should work as well as on Windows OS. Of course having both lines here is redundant, but we should not depend on a single developer machine’s OS in our source code. The alternative to that is just defining another &lt;code class=&quot;language-text&quot;&gt;docker-compose&lt;/code&gt; file and override the existing one depending on the development machine. Anyway, the principle is the same.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: If you’ve chosen Windows container when adding Docker support, you must change destination path to Windows pattern in volumes section.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;There are some dedicated NuGet packages which support secrets inside &lt;a href=&quot;https://docs.docker.com/engine/swarm/secrets/&quot;&gt;Docker swarm&lt;/a&gt;, but I’m not a fan of those. Your source code ought to be tools-agnostic so it shouldn’t know what development tools you’re using, whether it’s Docker, VMs or whatever.&lt;/p&gt;
&lt;h2&gt;Real-life suggestions&lt;/h2&gt;
&lt;p&gt;So if secrets are located only on my machine how the production app knows what are they? Of course we should place it on the production (or any remote environment) in some safety way during the deployment process. Very good solution is to use remote secrets vault (like Azure Key Vault or Vault from HashiCorp).&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Do we really need async?]]></title><description><![CDATA[The syntactic sugars are helpful features of C# language. We can use  instead of , we have common  instead of  loop with iterating…]]></description><link>https://blog.matjanowski.pl/2017/03/18/do-we-really-need-async/</link><guid isPermaLink="false">https://blog.matjanowski.pl/2017/03/18/do-we-really-need-async/</guid><pubDate>Sat, 18 Mar 2017 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The syntactic sugars are helpful features of C# language. We can use &lt;code class=&quot;language-text&quot;&gt;using(var tmp = new ...()) {}&lt;/code&gt; instead of &lt;code class=&quot;language-text&quot;&gt;Dispose()&lt;/code&gt;, we have common &lt;code class=&quot;language-text&quot;&gt;foreach&lt;/code&gt; instead of &lt;code class=&quot;language-text&quot;&gt;while&lt;/code&gt; loop with iterating enumerator, and we have &lt;code class=&quot;language-text&quot;&gt;await&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;async&lt;/code&gt;. But think a while… do we really need &lt;code class=&quot;language-text&quot;&gt;async&lt;/code&gt; word?&lt;/p&gt;
&lt;h2&gt;The world without async&lt;/h2&gt;
&lt;p&gt;Well, let’s look at the basic example of asynchronous method in C#:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;Task&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;AccessTheWebAsync&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;  
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;HttpClient&lt;/span&gt; client &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;HttpClient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;  
    &lt;span class=&quot;token class-name&quot;&gt;Task&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; getStringTask &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; client&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;GetStringAsync&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;http://msdn.microsoft.com&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;  
    &lt;span class=&quot;token function&quot;&gt;DoIndependentWork&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;  
  
    &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; urlContents &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; getStringTask&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;    
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; urlContents&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Length&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;  
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Await and async are always standing together in your code. The &lt;code class=&quot;language-text&quot;&gt;async&lt;/code&gt; indicates that the method is asynchronous so you can use &lt;code class=&quot;language-text&quot;&gt;await&lt;/code&gt; inside it. So far so good.&lt;/p&gt;
&lt;p&gt;But wait! If I can use await only in methods that returns &lt;code class=&quot;language-text&quot;&gt;Task&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;Task&amp;lt;T&gt;&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;void&lt;/code&gt; (for event handlers), why not to assume, that just using await word indicates this asynchronicity.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token return-type class-name&quot;&gt;Task&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;AccessTheWebAsync&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;  
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;HttpClient&lt;/span&gt; client &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;HttpClient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;  
    &lt;span class=&quot;token class-name&quot;&gt;Task&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; getStringTask &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; client&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;GetStringAsync&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;http://msdn.microsoft.com&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;  
    &lt;span class=&quot;token function&quot;&gt;DoIndependentWork&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;  
  
    &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; urlContents &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; getStringTask&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;    
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; urlContents&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Length&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;  
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The code above should work, as we have &lt;code class=&quot;language-text&quot;&gt;await&lt;/code&gt; keyword and return type is &lt;code class=&quot;language-text&quot;&gt;Task&amp;lt;int&gt;&lt;/code&gt;. Looks good. This guy is asynchronous. But wait again… what if… Damn!&lt;/p&gt;
&lt;h2&gt;Backward compatibility&lt;/h2&gt;
&lt;p&gt;Imagine, that you wrote code before .NET 4, when &lt;code class=&quot;language-text&quot;&gt;async&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;await&lt;/code&gt; didn’t exist in C#.&lt;/p&gt;
&lt;p&gt;You could have write a function like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;AddSomeObjects&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; bwait&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; bwait &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Looks good, isn’t it? It’s just adding two integers and returns a result. Even if we upgrade .NET to 4.5, the compiler can deduce, that await is an identifier. But consider this case:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;AddSomeObjects&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;CustomObj&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;CustomObj&lt;/span&gt; bwait&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; bwait&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;CustomObj&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token type-list&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;Task&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; Number &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

   &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;static&lt;/span&gt; CustomObj &lt;span class=&quot;token keyword&quot;&gt;operator&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;CustomObj&lt;/span&gt; o&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; 
   &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; 
     o&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Numeber &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; o&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Number &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
     &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;CustomObj&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;o&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;  
   &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
   
   &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;static&lt;/span&gt; CustomObj &lt;span class=&quot;token keyword&quot;&gt;operator&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;CustomObj&lt;/span&gt; o&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;CustomObj&lt;/span&gt; b&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; 
   &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; 
     &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt;&lt;/span&gt; res &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;CustomObj&lt;/span&gt;
                   &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                      Number &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; o&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Number &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; b&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Object&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                   &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
     &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; res&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; 
   &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This piece of code seems to be valid in older .NET, but if we want to use asychronous programming without &lt;code class=&quot;language-text&quot;&gt;async&lt;/code&gt; keyword, there is a clear ambiguity. In &lt;code class=&quot;language-text&quot;&gt;AddSomeObjects&lt;/code&gt; method old .NET would invoke obviously binary operator which adds &lt;code class=&quot;language-text&quot;&gt;Number&lt;/code&gt; properties of both objects and returns a new object with the new value. However, how should it behave in .NET 4.5? Should it return the same value as in the old .NET or should it wait for a result for &lt;code class=&quot;language-text&quot;&gt;bwait&lt;/code&gt; object with &lt;code class=&quot;language-text&quot;&gt;Number&lt;/code&gt; property incremented by 1?&lt;/p&gt;
&lt;p&gt;Essentially that’s the reason why Microsoft introduced &lt;code class=&quot;language-text&quot;&gt;async&lt;/code&gt; – to keep backward compatibility by enforcing implicit declaration that a method invokes asynchronous code.&lt;/p&gt;
&lt;h2&gt;&lt;code class=&quot;language-text&quot;&gt;async&lt;/code&gt; as a variable name&lt;/h2&gt;
&lt;p&gt;I like simple syntax in languages, so I believe that this artificial impediment could be avoided, but being more restrictive on upgrading to C# 5. The simple solution is just forbidding to use await keyword as a variable identifier. Microsoft didn’t do that, so we can have a method like this, which has valid syntax:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Test&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In my opinion, if someone does so big step as moving to new version of a platform, (s)he’s prepared for some changes. Why not do require so simple one, like renaming identifiers?&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How to change language in Visual Studio 2017/2019]]></title><description><![CDATA[Engineers love the new tools – that’s a fact. New IDE release is kind of Christmast Eve for all developers of a platform. Releasing Visual…]]></description><link>https://blog.matjanowski.pl/2017/03/11/how-to-change-language-in-visual-studio-2017/</link><guid isPermaLink="false">https://blog.matjanowski.pl/2017/03/11/how-to-change-language-in-visual-studio-2017/</guid><pubDate>Sat, 11 Mar 2017 22:12:03 GMT</pubDate><content:encoded>&lt;p&gt;Engineers love the new tools – that’s a fact. New IDE release is kind of Christmast Eve for all developers of a platform. Releasing Visual Studio 2017 is not an exception!&lt;/p&gt;
&lt;p&gt;It has tens of cool features which are widely described all over the Internet. The problem is, that those tutorials and reviews are all in English and my Visual Studio installed in… a default language of my system – Polish.&lt;/p&gt;
&lt;p&gt;I can’t get so deep into a idea of translating IDE, so I will just leave it without comment, so let’s go to the instruction.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First, go to the VisualStudio Installer – a little app which handles this bold venture called “Instalation of Visual Studio”. You can find it here:
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;On the top you have an installed version of VS. Click translation of “Modify” in your current language. In my case “Modyfikuj”.
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/784587e0fb2769568dbc2bc532dc72d6/2bef9/modify1.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 55.69620253164557%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAIAAADwazoUAAAACXBIWXMAAAsTAAALEwEAmpwYAAABQ0lEQVR42pVSSXKDMBDk/y/KN3JITAFyAMfs2heEhEQG7FT5EFc5U4JDq5ueHibxLghscC+VsNu2xRdOiNF575xLnFulNKsPYQ3bvyrGxPmVSg2feYWvtW6apu97xhjnPAk+ciopYxIaF8Ja+8QG+t1AkJ4+8yxDCA3DkACkOKNji6e94Np7/5d4fwupsnNVfbegJISAOJxq+vY+UkKtXcJRz5yFkFlxztFXWZa7GAaFucY6rGs4GPFJ23fntKgyVF7qGmOceB8VV9ZIrZU2Cn5B3OIKoDCAwGOMXoF0dxaoyOu6ruoLZNwzU6au3dhPtBvJiCmMFMCJCAAJk4QrocyyLAAyLj7SPM3Pl2YgjO9iu3htHjbkMJlnZ+blWIm958fMBULXa0P3zLc0B+EQxt9NuiO3IdxIyszdiLuJtj1uu+EHvgV8mtK9ZRMAAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Choose language packages screen&quot;
        title=&quot;&quot;
        src=&quot;/static/784587e0fb2769568dbc2bc532dc72d6/f058b/modify1.png&quot;
        srcset=&quot;/static/784587e0fb2769568dbc2bc532dc72d6/c26ae/modify1.png 158w,
/static/784587e0fb2769568dbc2bc532dc72d6/6bdcf/modify1.png 315w,
/static/784587e0fb2769568dbc2bc532dc72d6/f058b/modify1.png 630w,
/static/784587e0fb2769568dbc2bc532dc72d6/40601/modify1.png 945w,
/static/784587e0fb2769568dbc2bc532dc72d6/2bef9/modify1.png 1024w&quot;
        sizes=&quot;(max-width: 630px) 100vw, 630px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;You will see a list of components installed in your Visual Studio version. Choose another tab, an equivalent of “Language Packages”. In my case “Pakiety językowe”.
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/2f6b83746747b73035ad5de3d6079ee7/2bef9/languages.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 55.69620253164557%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAIAAADwazoUAAAACXBIWXMAAAsTAAALEwEAmpwYAAABj0lEQVR42n1R226bQBTc//+gqI9tH6JYji+AgwGbqlVsySTZ+5WF2p2FNKrUqqPZFVr2zJkzSx4fV/k236yzLCuKYlfkebkDnv7JGfidZfnDw4Ks8n0ne0bp5dIx+sZOLXs+eC1jHGLsI9Yf8KF3fQx9f7vdmuZAFtvqeyeNltokaK2dd0qo18sr41CjnHMhRAgBYlLbjmuuzM9xPB5bUtWNMZYxKiYopSEcAhi899jRcJwAF9ZYzhmINlVdk0PdeIcjLqVMxVKhBldvfwGHUINBKeQwDMl22RyV9UpK+xso9n00LsxjhEkLQIH10VgHV9Bq25Y81UfpAgKTUk1T2z54YfyLQAcBR5CbY0uzxOF6vc6+2vYbadrKBsUom0EpHcZRCvbSnTEcnaBUmiXG8U3o8/l8Op0o4/uqJk25C5pL9Y65j/fJ28cLfcQmpPrxnMrhqNxXpCx2WsCyVsogamMcUplijlPmM9O3c+kFQFyDVoXOn798zfJitV6vN5tErM32P8TF5XJ5f7+4u/v0C7wDX5Jc9YoLAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Choose languages option screen&quot;
        title=&quot;&quot;
        src=&quot;/static/2f6b83746747b73035ad5de3d6079ee7/f058b/languages.png&quot;
        srcset=&quot;/static/2f6b83746747b73035ad5de3d6079ee7/c26ae/languages.png 158w,
/static/2f6b83746747b73035ad5de3d6079ee7/6bdcf/languages.png 315w,
/static/2f6b83746747b73035ad5de3d6079ee7/f058b/languages.png 630w,
/static/2f6b83746747b73035ad5de3d6079ee7/40601/languages.png 945w,
/static/2f6b83746747b73035ad5de3d6079ee7/2bef9/languages.png 1024w&quot;
        sizes=&quot;(max-width: 630px) 100vw, 630px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Simply Select “English” (“Angielski”), and to be honest I recommend you to deselect others.
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/96b92a287e9a5cf30c3505bc7727ae85/2bef9/vs-change-language-1.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 55.69620253164557%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAIAAADwazoUAAAACXBIWXMAAAsTAAALEwEAmpwYAAABK0lEQVR42o2SS1PCMBSF+//XLt26c+M/wBllcAZaApEGBKljy4Cl6StJW5Im3rRL7cA3J6+bnOQs4kyn7gJhz1sgtFwuMchfrTB+HxKAMUZoMZm8OWiOaEKTc3w6ndKUHmN6+Emrurn8B5RFDX1jjNlsPpwN8eMwYOeD1lAxrTYKmukWf6gv8kjLtGCtUtvtzgmCQHAOMjegpKQ0gYCMMbJeWzPnvOmSXEVrXZRlnudSSht7v7dmIYTW+qq5kbrkoqlrmO92XWzZcVNsbR9XSnXmTzB/9XluMWdMRFEUhmFCqU/WNnZnbu0Fw7RtC8cYF8E32KMizwghju8TIaqy5IwJxmxfVfWQevIsi2kBn8oZjZ7nCM1mrut6vTxvPiTYheHldXz3OL5/ePoFpD5qGgKQv6wAAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;img
        class=&quot;gatsby-resp-image-image&quot;
        alt=&quot;Choose languages screen&quot;
        title=&quot;&quot;
        src=&quot;/static/96b92a287e9a5cf30c3505bc7727ae85/f058b/vs-change-language-1.png&quot;
        srcset=&quot;/static/96b92a287e9a5cf30c3505bc7727ae85/c26ae/vs-change-language-1.png 158w,
/static/96b92a287e9a5cf30c3505bc7727ae85/6bdcf/vs-change-language-1.png 315w,
/static/96b92a287e9a5cf30c3505bc7727ae85/f058b/vs-change-language-1.png 630w,
/static/96b92a287e9a5cf30c3505bc7727ae85/40601/vs-change-language-1.png 945w,
/static/96b92a287e9a5cf30c3505bc7727ae85/2bef9/vs-change-language-1.png 1024w&quot;
        sizes=&quot;(max-width: 630px) 100vw, 630px&quot;
        style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
        loading=&quot;lazy&quot;
        decoding=&quot;async&quot;
      /&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Click “Modify” on the right bottom and wait for process to be finished.&lt;/li&gt;
&lt;li&gt;Run your Visual Studio 2017 again – you have English version now.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I hope it helped! Cheers!&lt;/p&gt;
&lt;p&gt;UPDATE: Recently VS 2019 has been released. Changing the language in this version is pretty much the same as in VS 2017.&lt;/p&gt;</content:encoded></item></channel></rss>