<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Georg Müller</title>
    <description>The latest articles on DEV Community by Georg Müller (@ggmueller).</description>
    <link>https://dev.to/ggmueller</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1342%2F43e9e1a7-a699-4671-926b-8f2cd2d89c5e.JPG</url>
      <title>DEV Community: Georg Müller</title>
      <link>https://dev.to/ggmueller</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ggmueller"/>
    <language>en</language>
    <item>
      <title>Branding a multitenated application using CSS</title>
      <dc:creator>Georg Müller</dc:creator>
      <pubDate>Sun, 09 Jan 2022 14:20:43 +0000</pubDate>
      <link>https://dev.to/ggmueller/branding-a-multitenated-application-using-css-58m7</link>
      <guid>https://dev.to/ggmueller/branding-a-multitenated-application-using-css-58m7</guid>
      <description>&lt;p&gt;A friend of mine had an interesting challenge. He wanted to have a public part of an B2B application brandable in the color of its customers and asked me how I would do it. This post describes what I told him.&lt;/p&gt;

&lt;p&gt;The application basically is a simple form and a summary describing the data the user will submit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Base setup in the CSS
&lt;/h2&gt;

&lt;p&gt;Use CSS variables for the colors and use them consistently where you want the brands colors to be applied.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--brand-color-1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;66&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;153&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;225&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;--brand-color-2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I this case I created a themable button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--brand-color-1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;border-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--brand-color-2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--brand-color-2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6px&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt; &lt;span class="m"&gt;6px&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks like this: &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2MeGNsIq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjr6i7blv4nqemdqo7va.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2MeGNsIq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjr6i7blv4nqemdqo7va.png" alt="Button with blue background" width="120" height="47"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Use CSS inheritance to override the color
&lt;/h2&gt;

&lt;p&gt;In CSS properties are inherited from the root element to its child elements. &lt;br&gt;
In this case I would override it on body as I would like to have all elements using the overridden colors, eg like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;body&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"--brand-color-1: #48BB78"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bqj_SGMn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csce8ua46szeg7gtk07b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bqj_SGMn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csce8ua46szeg7gtk07b.png" alt="Button with green background" width="128" height="54"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can override the color on the html using your web framework of choice.&lt;/p&gt;

&lt;p&gt;If you are rendering on the server you should be aware of caching. You would probably like to cache by tenant and make sure you invalidate when changing the colors, but that is out of scope for this post.&lt;/p&gt;

&lt;p&gt;If you want to play around with this solution I made a codepen: &lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/ggmueller/embed/eYGLRrb?height=600&amp;amp;default-tab=html,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Concluding
&lt;/h2&gt;

&lt;p&gt;This is a solution by a backend developer :-). Do you know of a better solution?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
    </item>
    <item>
      <title>Modularize ASP.NET DI configurations using Autofac</title>
      <dc:creator>Georg Müller</dc:creator>
      <pubDate>Sun, 14 Nov 2021 16:27:29 +0000</pubDate>
      <link>https://dev.to/ggmueller/modularize-aspnet-di-configurations-using-autofac-1ab6</link>
      <guid>https://dev.to/ggmueller/modularize-aspnet-di-configurations-using-autofac-1ab6</guid>
      <description>&lt;p&gt;When working on a monolith in ASP.NET the &lt;code&gt;Startup.cs&lt;/code&gt; tends to get messy as more and more services are added.&lt;/p&gt;

&lt;p&gt;Nevertheless, with the Microsoft.Extensions.DependencyInjection being the new and good default for libraries to provide means for configuration, I want to use these extension methods to setup my dependency injection container of choice, which is &lt;a href="https://autofac.org"&gt;Autofac&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Modularizing the configuration in Autofac
&lt;/h2&gt;

&lt;p&gt;Autofac always provided means to easily modularize its configuration using &lt;code&gt;Module&lt;/code&gt;s.&lt;/p&gt;

&lt;p&gt;Basically you add a new class inheriting from Module and override &lt;code&gt;Load&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AModule&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Module&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ContainerBuilder&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RegisterType&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;MyType&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you are registering the module in the configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;RegisterAssemblyModules&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Startup&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;Assembly&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Register all modules in assembly&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;RegisterModule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AModule&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Register single module&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RegisterModule&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;AModule&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Register single module using generics&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Integrating Microsoft.Extensions.DependendyInjection registrations with Autofac Modules
&lt;/h2&gt;

&lt;p&gt;Autofacs integration with Microsofts DependencyInjection (&lt;a href="https://github.com/autofac/Autofac.Extensions.DependencyInjection"&gt;https://github.com/autofac/Autofac.Extensions.DependencyInjection&lt;/a&gt;) adds an &lt;code&gt;PopulateServices&lt;/code&gt; extension that allows to add all services in an IServiceCollection to the Autofac configuration.&lt;/p&gt;

&lt;p&gt;When adding Autofac to an ASP.NET application this method is used at the end to integrate the &lt;code&gt;Microsoft.Extensions.DependencyInjection&lt;/code&gt; services into Autofac.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Populate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;ContainerBuilder&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ServiceDescriptor&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;descriptors&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method can also be used in modules to add additional services to the container in a modular fashion. Here an example for a ValidationModule that adds &lt;code&gt;FluentValidation&lt;/code&gt; to the application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ValidationModule&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Module&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ContainerBuilder&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ServiceCollection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddFluentValidation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fv&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;fv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;RegisterValidatorsFromAssembly&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ThisAssembly&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Populate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method allows you to use extension methods provided by libraries for an easier integration into the .NET ecosystem in a modular, clean way located close to the code that needs it.&lt;/p&gt;

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

&lt;p&gt;I have shown how I integrate Autofacs Module configuration with &lt;code&gt;Microsoft.Extensions.DependencyInjection&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;I use this method to modularize the configuration for my monolithic applications.&lt;/p&gt;

&lt;p&gt;How are you managing your growing Startup.cs? Have you found another way to manage your dependencies in a better way? &lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>autofac</category>
    </item>
    <item>
      <title>Running Linux Containers on WSL using Nomad</title>
      <dc:creator>Georg Müller</dc:creator>
      <pubDate>Sat, 28 Aug 2021 16:15:09 +0000</pubDate>
      <link>https://dev.to/ggmueller/running-linux-containers-on-wsl-using-nomad-80o</link>
      <guid>https://dev.to/ggmueller/running-linux-containers-on-wsl-using-nomad-80o</guid>
      <description>&lt;p&gt;&lt;a href="https://nomadproject.io" rel="noopener noreferrer"&gt;Hashicorp Nomad&lt;/a&gt; is a workload orchestration engine that allows you to deploy and operate workloads on multiple machines or VMs.&lt;/p&gt;

&lt;p&gt;As such Nomad is a direct competitor to Kubernetes. In contrast to Kubernetes, Nomad allows to orchestrate not only containerized workloads, but also all kinds of non-containerized workloads like simple Linux processes, Java applications, Windows (IIS) applications, ... .&lt;/p&gt;

&lt;p&gt;While it is flexible, it is also more simple than Kubernetes.&lt;/p&gt;

&lt;p&gt;So recently I started looking into Nomad.&lt;/p&gt;

&lt;p&gt;I set up Nomad on my Windows machine using chocolatey using&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Starting Nomad using, to setup a development agent&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nomad agent -dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this successfully started Nomad, it did not start its &lt;a href="https://www.nomadproject.io/docs/drivers/docker" rel="noopener noreferrer"&gt;Docker Task Driver&lt;/a&gt;, which allows to place Docker container in the Nomad Cluster. The error in the log was:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Docker is configured with Linux containers; switch to Windows containers&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Searching for a solution I found this issue in the repo: &lt;a href="https://github.com/hashicorp/nomad/issues/2633" rel="noopener noreferrer"&gt;Support Linux images in Docker for Windows&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Basically the issue says, that the integration should work, but it is not being verified in tests. It also seems like some people got it to work while some are not.&lt;/p&gt;

&lt;p&gt;I really don't see however, how someone could get this to run, as the fingerprinter of the docker container driver always throws an error: &lt;a href="https://github.com/hashicorp/nomad/blob/42666b80143709cc6dd4ec7270706a06978e2a78/drivers/docker/fingerprint.go#L175" rel="noopener noreferrer"&gt;fingerprint.go&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some weeks later, I decided to take a different approach installing Nomad directly into the WSL Linux distribution. This allowed me to run Linux containers, while not having to launch an additional VM. These are the required steps.&lt;/p&gt;

&lt;h1&gt;
  
  
  Steps to get the Docker Task Driver working
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Install Docker for Desktop&lt;/li&gt;
&lt;li&gt;Start Docker for Desktop and make sure you have the Linux Kernel package installed; Docker will open a Microsoft website where you can find the download&lt;/li&gt;
&lt;li&gt;Make sure you have the WSL2 backend enabled in Docker for Desktop - Settings
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FAocXzAd.png" alt="Docker for Desktop - General - Use the WSL2 based engine"&gt;
&lt;/li&gt;
&lt;li&gt;Download a Linux Distro from Microsoft Store, I have been using Ubuntu 20.04&lt;/li&gt;
&lt;li&gt;Install Ubuntu&lt;/li&gt;
&lt;li&gt;Make sure Ubuntu is the Default Linux Distro in WSL using
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wsl -s Ubuntu-20.04
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Enable WSL integration for Ubuntu in the Docker for Desktop settings; you find it in Settings &amp;gt; Resources &amp;gt; WSL integration
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FrH8taiN.png" alt="Docker for Desktop - Settings - Resources - WSL integration - Ubuntu 20.04 enabled"&gt;
&lt;/li&gt;
&lt;li&gt;Install Nomad in Ubuntu (see &lt;a href="https://www.nomadproject.io/docs/install" rel="noopener noreferrer"&gt;Nomad docs&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Start it using
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nomad agent -dev --bind=0.0.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This successfully started Nomad (1.1.3 at time of writing)&lt;/li&gt;
&lt;li&gt;A look in the log confirmed the Docker Task Driver started
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[DEBUG] client.driver_mgr: detected drivers: drivers="map[healthy:[raw_exec docker] undetected:[exec java qemu]]"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If Docker is not detected at this point check your user is in the docker group using&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;If you cannot see the docker group, add it using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo usermod -aG docker $USER
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then restart WSL by exiting the shell.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test
&lt;/h2&gt;

&lt;p&gt;Finally a quick test, its very easy to test if you can deploy a container to Nomad.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This creates a example.nomad file, that includes all configurations to deploy a Linux Redis container.&lt;/p&gt;

&lt;p&gt;Running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nomad run example.nomad
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;starts the deployment and successfully starts the container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  ✓ Deployment "d3935b56" successful

    2021-08-04T14:13:54+02:00
    ID          = d3935b56
    Job ID      = example
    Job Version = 0
    Status      = successful
    Description = Deployment completed successfully

    Deployed
    Task Group  Desired  Placed  Healthy  Unhealthy  Progress Deadline
    cache       1        1       1        0          2021-08-04T14:23:52+02:00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nice !!!!&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;p&gt;Make sure&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;you have an update version of Nomad, I am using 1.1.3 at the time of writing,&lt;/li&gt;
&lt;li&gt;WSL2 mode is activated in Docker settings,&lt;/li&gt;
&lt;li&gt;the distro is activated for WSL integration in Docker settings,&lt;/li&gt;
&lt;li&gt;and (not WSL specific, but I always tend to forget it) add your user to the Docker group in WSL&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;After several failed attempts, using this checklist I managed to successfully start Nomad jobs on 2 different PCs.  &lt;/p&gt;

</description>
      <category>nomad</category>
      <category>container</category>
      <category>windows</category>
      <category>wsl</category>
    </item>
    <item>
      <title>Deep Dive - Autofac Integration in ASP.NET Core Dependency Injection </title>
      <dc:creator>Georg Müller</dc:creator>
      <pubDate>Sun, 06 Sep 2020 15:54:36 +0000</pubDate>
      <link>https://dev.to/ggmueller/deep-dive-autofac-integration-in-asp-net-core-dependency-injection-3f3a</link>
      <guid>https://dev.to/ggmueller/deep-dive-autofac-integration-in-asp-net-core-dependency-injection-3f3a</guid>
      <description>&lt;p&gt;One thing that seemingly remains consistent, is that the integration of Autofac with ASP.NET keeps changing. Starting with ASP.NET Core 3.0 this changed, because  the generic host was introduced.&lt;/p&gt;

&lt;p&gt;I will quickly explore the usage of Autofac in ASP.NET and then dive a bit into the details of its core. Together with the implementation in ASP.NET Dependency Injection it is an interesting design, although not quite as obvious.&lt;/p&gt;

&lt;h1&gt;
  
  
  Installation and Usage
&lt;/h1&gt;

&lt;p&gt;Installation is simple. Reference &lt;code&gt;Autofac.Extensions.DependencyInjection&lt;/code&gt; in your ASP.NET application.&lt;/p&gt;

&lt;p&gt;To use Autofac in your application, go to the class that creates our &lt;code&gt;Host&lt;/code&gt;, typically this is your &lt;code&gt;Program.cs&lt;/code&gt; and insert &lt;code&gt;.UseServiceProviderFactory(new AutofacServiceProviderFactory())&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It could look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Program&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateDefaultBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;UseServiceProviderFactory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;AutofacServiceProviderFactory&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ConfigureWebHostDefaults&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;webBuilder&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;webBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UseStartup&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Startup&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;())&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

      &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This enables Autofac as DI container in your ASP.NET Core Application.&lt;/p&gt;

&lt;p&gt;Then you can add a &lt;code&gt;ConfigureContainer&lt;/code&gt; method to your &lt;code&gt;Startup&lt;/code&gt; class and configure the container using the &lt;code&gt;ContainerBuilder&lt;/code&gt; you are used to as Autofac user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;ConfigureContainer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ContainerBuilder&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;RegisterAssemblyModules&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Startup&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;Assembly&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The integration also supports taking dependencies on registration in the IServiceCollection. So if you have on library that only supports registration with the ASP.NET Dependency Injection you do not have to worry. You can use it in your application.&lt;/p&gt;

&lt;p&gt;These methods also support environment based naming conventions. I am not a fan of them but you can find the conventions in the Autofac &lt;a href="https://autofaccn.readthedocs.io/en/latest/integration/aspnetcore.html#configuration-method-naming-conventions"&gt;docs&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is registered?
&lt;/h1&gt;

&lt;p&gt;The core of the integration is the &lt;code&gt;AutofacServiceProviderFactory&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A ServiceProviderFactory is a abstraction within ASP.NET Dependency Injection. It allows Dependency Injection Frameworks to be used with ASP.NET, combining the advantage of having the an unified configuration for dependencies (useful for frameworks, so they only have to support one style of configuration), with the power of existing DI containers out there.&lt;/p&gt;

&lt;p&gt;So it has two purposes.&lt;/p&gt;

&lt;p&gt;First: It creates the DI container builder and populates it with dependencies from the ASP.NET ServiceCollection. The developer can then configure additional dependencies or replace the dependencies registered using the Autofac mechanisms. &lt;/p&gt;

&lt;p&gt;Second: It builds the container and wraps it as ServiceProvider to be used in the framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding scopes
&lt;/h2&gt;

&lt;p&gt;Working with DI containers and ASP.NET you will know that there are different scopes for objects and their dependencies.&lt;/p&gt;

&lt;p&gt;The basic cases are Singleton and PerDependency, where Singleton is on object per application is instantiated and PerDependency creates an object for every dependency that requires the object.&lt;/p&gt;

&lt;p&gt;In a HTTP framework you want to share some state application wide, but some dependencies should be once per request.&lt;/p&gt;

&lt;p&gt;An example would be an &lt;code&gt;UnitOfWork&lt;/code&gt; from an ORM. Once a dependency required it on the request, it should stay the same &lt;code&gt;UnitOfWork&lt;/code&gt; for the whole request.&lt;/p&gt;

&lt;p&gt;Therefore a &lt;code&gt;LifetimeScope&lt;/code&gt; (in Autofac terminology) or &lt;code&gt;ServiceScope&lt;/code&gt; (ASP.NET terminology) exists.&lt;/p&gt;

&lt;p&gt;It is created when a new Request starts and is disposed when the request is completed.&lt;/p&gt;

&lt;p&gt;ASP.NET needs a factory to create these &lt;code&gt;ServiceScope&lt;/code&gt;s. When populating the ContainerBuilder Autofac adds this factory (&lt;code&gt;AutofacServiceScopeFactory&lt;/code&gt;) to itself, so that ASP.NET can resolve it.&lt;/p&gt;

&lt;p&gt;Its also interesting how this is integrated in ASP.NET. When the HttpContext of a Request is constructed it gets a reference to the &lt;code&gt;ServiceScopeFactory&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The first time a service is resolved from the request it instantiates the &lt;code&gt;ServiceScope&lt;/code&gt;, thus resolving all the dependencies configured for this scope.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;The Autofac integration is implemented as it is expected from a DI container implementation for ASP.NET Core. &lt;/p&gt;

&lt;p&gt;What is most interesting, is how the container registers its own implementations in itself, in order for ASP.NET to resolve it.&lt;/p&gt;

&lt;p&gt;When debugging this a few months ago I missed this detail, thus suspecting an error of mine to be in the DI integration. Obviously I was wrong...&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>autofac</category>
    </item>
  </channel>
</rss>
