<?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: Niklas Engberg</title>
    <description>The latest articles on DEV Community by Niklas Engberg (@engberrg).</description>
    <link>https://dev.to/engberrg</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%2F63368%2F4bd1552d-d4a8-43b3-8cc1-14caf1f1bd97.jpg</url>
      <title>DEV Community: Niklas Engberg</title>
      <link>https://dev.to/engberrg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/engberrg"/>
    <language>en</language>
    <item>
      <title>How to fix the nasty ‘bash: ./wait-for-it.sh: Is a directory’ on Windows</title>
      <dc:creator>Niklas Engberg</dc:creator>
      <pubDate>Sat, 29 Jun 2019 17:02:06 +0000</pubDate>
      <link>https://dev.to/engberrg/how-to-fix-the-nasty-bash-wait-for-it-sh-is-a-directory-on-windows-bk6</link>
      <guid>https://dev.to/engberrg/how-to-fix-the-nasty-bash-wait-for-it-sh-is-a-directory-on-windows-bk6</guid>
      <description>&lt;h3&gt;
  
  
  How to fix the nasty ‘bash: ./wait-for-it.sh: Is a directory’ on Windows 💪
&lt;/h3&gt;

&lt;p&gt;Nowadays when building applications they’re usually built using a distributed microservice architecture that consists of many services. Many of those services have dependencies on other services, usually infrastructure that needs to be booted before. To manage multiple services in an controlled an easy way &lt;a href="https://www.docker.com/"&gt;Docker&lt;/a&gt; and &lt;a href="https://docs.docker.com/compose/"&gt;Docker Compose&lt;/a&gt; can help you.&lt;/p&gt;

&lt;p&gt;Docker Compose is a tool for defining and running multi-container Docker applications. What is limited though is to know when a container is ready to start accepting traffic. You can &lt;a href="https://docs.docker.com/compose/startup-order/"&gt;control startup order&lt;/a&gt; of containers by using depends_on. So for instance:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
   service1:
     ...omitted
     depends\_on:
     - "rabbitmq"

   rabbitmq:
     ...omitted
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will only verify that the container is running before service1 boots. To ensure that you do not start your container before the dependency is ready to accept traffic &lt;a href="https://github.com/vishnubob/wait-for-it"&gt;wait-for-it&lt;/a&gt; is a good script to use.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
  service1:
    ...omitted
    volumes:
      - "./scripts/wait-for-it.sh:/app/wait-for-it.sh"
    entrypoint: ["bash", "-c", "./wait-for-it.sh rabbitmq:15672 -t 0; ./start.sh"]

  rabbitmq:
     ...omitted
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will make sure that the rabbitmq service is available on port 15672 before the next script is executed (in this case a simple start.sh-file). This approach usually works very well but you can run into trouble when you are mainly developing on Windows:&lt;/p&gt;

&lt;p&gt;bash: ./wait-for-it.sh: Is a directory&lt;/p&gt;

&lt;p&gt;In this post I will share how I have solved this issue. I’ve spent maaany hours troubleshooting so hopefully I can save you some time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Wrong line endings
&lt;/h3&gt;

&lt;p&gt;Your wait-for-it.sh file is using windows line endings (CRLF). Files created on Windows have different line endings than files created on Unix. If you are running Linux containers you need to make sure your script file uses LF and not CRLF. You can easily find out by opening the file in some modern text editor like Notepad++ or VSCode.&lt;/p&gt;

&lt;h4&gt;
  
  
  Line endings in repository
&lt;/h4&gt;

&lt;p&gt;You probably version your software and when you are using git there is a setting that you can configure to &lt;a href="https://help.github.com/en/articles/dealing-with-line-endings"&gt;handle line endings&lt;/a&gt;. If you are collaborating across platforms you usually have the setting configured to auto. That means that any time you add a file to the git repo that git thinks is a text file, it will turn all CRLF line endings to just LF before it stores it in the commit. Whenever you dogit checkout, all text files automatically will have their LF line endings converted to CRLF endings.&lt;/p&gt;

&lt;p&gt;Make sure you have a present .gitattributes file in your repo that has this setting:&lt;/p&gt;

&lt;p&gt;*.sh text eol=lf&lt;/p&gt;

&lt;p&gt;This will tell git to apply LF line endings to all .sh files when checking out.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shared drive
&lt;/h3&gt;

&lt;p&gt;Make sure you share your driver(s). In the example above I am using a &lt;a href="https://docs.docker.com/storage/volumes/"&gt;host volume mount&lt;/a&gt; to share files from my host into the container. To be able to do this you need to share your drive. You can do this in the Docker Settings by right clicking the icon in the tray.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u1P32SfF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/832/1%2A4p-0nXQRdporXyvzfJaNmg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u1P32SfF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/832/1%2A4p-0nXQRdporXyvzfJaNmg.png" alt=""&gt;&lt;/a&gt;&lt;a href="https://token2shell.com/img/howto/token2shell/docker/docker-settings-shared-drives.png"&gt;&lt;/a&gt;&lt;a href="https://token2shell.com/img/howto/token2shell/docker/docker-settings-shared-drives.png"&gt;https://token2shell.com/img/howto/token2shell/docker/docker-settings-shared-drives.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our environment (I assume that this might be the case for you) we are using specific local admin accounts for elevated permissions. To be able to share your drive you need authenticate using this account. When the password for this local account expires, Docker won’t tell you or prompt you again to enter your password — &lt;em&gt;unless&lt;/em&gt; you untick the box, hit apply, tick the box and hit apply again. Frustrating!&lt;/p&gt;

&lt;p&gt;Hopefully when you have fixed the line endings and shared your driver(s) your issue will go away and you’ll see something like this:&lt;/p&gt;

&lt;p&gt;service1 | wait-for-it.sh: waiting for rabbitmq:15672 without a timeout&lt;/p&gt;

&lt;p&gt;These are two things that might bite you. Hopefully I have saved you some time troubleshooting! 😆&lt;/p&gt;




</description>
      <category>docker</category>
      <category>coding</category>
      <category>containers</category>
      <category>dockercompose</category>
    </item>
    <item>
      <title>My way of working with internal nuget packages</title>
      <dc:creator>Niklas Engberg</dc:creator>
      <pubDate>Mon, 26 Nov 2018 14:36:01 +0000</pubDate>
      <link>https://dev.to/engberrg/my-way-of-working-with-internal-nuget-packages-5gn5</link>
      <guid>https://dev.to/engberrg/my-way-of-working-with-internal-nuget-packages-5gn5</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AA4sh2W_Gt5OWFg3HHzwXPw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AA4sh2W_Gt5OWFg3HHzwXPw.png"&gt;&lt;/a&gt;Picture borrowed from &lt;a href="https://cdn.pixabay.com/photo/2013/07/13/10/22/box-157074_1280.png" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://cdn.pixabay.com/photo/2013/07/13/10/22/box-157074_1280.png" rel="noopener noreferrer"&gt;https://cdn.pixabay.com/photo/2013/07/13/10/22/box-157074_1280.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The company I’m working at is big enough to span over multiple development teams. To be able to share a common way of working and to prevent that the wheel is invented over and over we rely on shared &lt;a href="https://docs.microsoft.com/en-us/nuget/what-is-nuget" rel="noopener noreferrer"&gt;nuget&lt;/a&gt; packages.&lt;/p&gt;

&lt;p&gt;I am author of many packages and the main contributor of those and that requires me to spend some time maintaining them. To be able to do this I need a working method that enables me to do this efficiently.&lt;/p&gt;

&lt;p&gt;In this post I’m going to share my way of doing this, step by step.&lt;/p&gt;

&lt;h4&gt;
  
  
  Version control
&lt;/h4&gt;

&lt;p&gt;To version control the packages &lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;git&lt;/a&gt; is used. Git is a &lt;em&gt;de facto standard&lt;/em&gt; and need no further description :)&lt;/p&gt;

&lt;h4&gt;
  
  
  Naming
&lt;/h4&gt;

&lt;p&gt;Decide on a good naming convention that will work for you. We use a prefix with our company separated by points narrowing down. For instance: CompanyA.AspNetCore.Mvc would be our own package with custom classes for ASP.NET Core MVC.&lt;/p&gt;

&lt;h4&gt;
  
  
  Project structure
&lt;/h4&gt;

&lt;p&gt;To stay consistent a project structure should be used. I base mine on this &lt;a href="https://gist.github.com/davidfowl/ed7564297c61fe9ab814" rel="noopener noreferrer"&gt;Gist&lt;/a&gt; by David Fowler. It is not strictly followed, but rather inspired by. For example, the test project is not separated into its own test folder, instead it is included in the src folder. This setup is done once, when I introduce additional packages I just copy the structure from another project. This structure could easily be extracted into a &lt;a href="https://docs.microsoft.com/en-us/dotnet/core/tools/custom-templates" rel="noopener noreferrer"&gt;dotnet template&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nuspec file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://docs.microsoft.com/en-us/nuget/reference/nuspec" rel="noopener noreferrer"&gt;this&lt;/a&gt;reference by adding your nuspec file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tests&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Make sure you cover your packages with unit tests. That will give you confidence that your code works as you expect it to work and will also help other contributors. I’m using &lt;a href="https://xunit.github.io/" rel="noopener noreferrer"&gt;xUnit&lt;/a&gt; and in some projects &lt;a href="https://github.com/AutoFixture/AutoFixture" rel="noopener noreferrer"&gt;AutoFixture&lt;/a&gt; to maximize maintainability and reduce code in the Arrange phase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Documentation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add a README.md to the project that explains how to use the package. More on the README.md below in the section about &lt;em&gt;Crafting the package&lt;/em&gt;. I am considering looking into &lt;a href="https://readthedocs.org/" rel="noopener noreferrer"&gt;Read the Docs&lt;/a&gt; as a complement.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to introduce changes?
&lt;/h4&gt;

&lt;p&gt;The workflow that is used is &lt;a href="https://nvie.com/posts/a-successful-git-branching-model/" rel="noopener noreferrer"&gt;Git Flow&lt;/a&gt; which means that we do not directly push changes to the master branch, but rather to feature branches that we integrate against the develop branch. I am not going to go into detail about Git Flow here.&lt;/p&gt;

&lt;p&gt;When a feature is done, a pull request is opened and stakeholders are invited. And hopefully the feature is merged back to develop and ready for the next upcoming release. The git tag should reflect the version to be released. I explain my process of doing this in the section &lt;em&gt;Crafting the package.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Breaking changes or not?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, what is a breaking change?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A change in one part of a &lt;a href="https://en.wiktionary.org/wiki/software" rel="noopener noreferrer"&gt;software&lt;/a&gt; system that potentially causes other components to &lt;a href="https://en.wiktionary.org/wiki/fail" rel="noopener noreferrer"&gt;fail&lt;/a&gt;; occurs most often in shared libraries of code used by multiple applications — &lt;a href="https://en.wiktionary.org/wiki/breaking_change" rel="noopener noreferrer"&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you alter the definition of an existing method that you are exposing to the consumer or remove properties from an object that is a breaking change. Please make sure you have a consuming test client targeting your packages so that you can verify that the changes you’ve made are correctly done.&lt;/p&gt;

&lt;p&gt;When it’s time to update an already existing package you need to take your consumers into consideration. You need to ask yourself if it’s a breaking change or not that you are introducing. If it isn’t, then it’s fine. That change should then only alter the minor and/or patch version.&lt;/p&gt;

&lt;p&gt;If you are about to introduce a breaking change you need to keep support for the deprecated feature at least one version before removing it. I tend to do it this way&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add the new feature&lt;/li&gt;
&lt;li&gt;Deprecate the old feature by adding an &lt;a href="https://docs.microsoft.com/en-us/dotnet/api/system.obsoleteattribute.message?view=netcore-2.1" rel="noopener noreferrer"&gt;ObsoleteAttribute&lt;/a&gt; and describe how the consumer should migrate.&lt;/li&gt;
&lt;li&gt;Bump the minor version and release a new version&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the next major release, remove the obsoleted feature. In this way the consumer is given some time to migrate their existing code to use the new version.&lt;/p&gt;

&lt;h4&gt;
  
  
  Crafting the package
&lt;/h4&gt;

&lt;p&gt;Before publishing a new package I make sure that&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The dependencies in the nuspec file is updated and that the supported target frameworks are in place&lt;/li&gt;
&lt;li&gt;The README.md is updated with new functionality and examples&lt;/li&gt;
&lt;li&gt;Versioning is correct&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Dependencies in nuspec&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There is a section in the nuspec file manifest that enabled to specify the &lt;a href="https://docs.microsoft.com/en-us/nuget/reference/nuspec#dependencies" rel="noopener noreferrer"&gt;dependencies&lt;/a&gt; that the package has. Even if packages only support one target framework they are included in a &lt;a href="https://docs.microsoft.com/en-us/nuget/reference/nuspec#dependency-groups" rel="noopener noreferrer"&gt;dependency group&lt;/a&gt;. That makes it easy in the future to add additional target frameworks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Updating the README.md&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To make sure that I update the README.md so that it is easy to follow I use &lt;a href="https://markdownlivepreview.com/" rel="noopener noreferrer"&gt;Markdown Live Preview&lt;/a&gt; when editing it. That gives me a visual editor on how the file will be displayed. I then copy the content into my README.md and commit it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Versioning the package&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I’m using &lt;a href="https://semver.org/" rel="noopener noreferrer"&gt;semantic versioning&lt;/a&gt;. To version the package the numbers must be consistent in *.csproj, .nuspec and in the git repository. For this I’m utilizing custom made PowerShell scripts.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This is executed by running it from the src folder.&lt;/p&gt;

&lt;p&gt;.\bump-assembly-version.ps1 -Version 0.0.1&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This is excuted by running it from the src folder.&lt;/p&gt;

&lt;p&gt;.\bump-nuspec-version-ps1 -Version 0.0.1&lt;/p&gt;

&lt;p&gt;I then commit those changes&lt;/p&gt;

&lt;p&gt;git commit -am "Incremented project version"&lt;/p&gt;

&lt;p&gt;Before pushing anything I make sure that my repository is tagged with the same version so that we have a tag that corresponds to the release&lt;/p&gt;

&lt;p&gt;git tag -a 0.0.1 -m "Release 0.0.1"&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(All of the above could easily be built into one single script file. I still do it separately but might consolidate in the future :))&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And then push the tag&lt;/p&gt;

&lt;p&gt;git push origin 0.0.1&lt;/p&gt;

&lt;p&gt;And the code&lt;/p&gt;

&lt;p&gt;git push&lt;/p&gt;

&lt;h4&gt;
  
  
  Publishing the package
&lt;/h4&gt;

&lt;p&gt;There are different ways you can do this. Either locally using the nuget CLI to push the package to your feed, or let your CI service do this work.&lt;/p&gt;

&lt;p&gt;I am letting &lt;a href="https://azure.microsoft.com/nb-no/services/devops/" rel="noopener noreferrer"&gt;Azure DevOps&lt;/a&gt; and Azure Pipelines do this. The build process consist of standard .NET build / run tests tasks. If you are interested in how that might look you can find examples &lt;a href="https://github.com/MicrosoftDocs/pipelines-dotnet-core" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally the nuget package is crafted based on the nuspec file. The package is then pushed to our internal nuget feed. For this to work seamless a service connection to our nuget feed is added in Azure DevOps. The package manager that is used is &lt;a href="https://inedo.com/proget" rel="noopener noreferrer"&gt;ProGet&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When this package published I usually notify all the developers on Slack that new packages are available and take any further discussions from there.&lt;/p&gt;

&lt;p&gt;This is a process that is working for me. If you have any opinions or other ways of doing this I’d like to hear. What features should be extracted into nuget packages really depends on your company and how you share code between team. I prefer to have a consistent way of doing things and I’ve noticed that we save a lot of time in our projects if we can reuse good things that others already have built.&lt;/p&gt;

&lt;p&gt;If you liked the post, you know what to do! 👏&lt;/p&gt;




</description>
      <category>powershell</category>
      <category>packaging</category>
      <category>internalnugetpacka</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>MediatR behaviors to validate API Resource existence</title>
      <dc:creator>Niklas Engberg</dc:creator>
      <pubDate>Wed, 12 Sep 2018 14:42:09 +0000</pubDate>
      <link>https://dev.to/engberrg/mediatr-behaviors-to-validate-api-resource-existence-5c04</link>
      <guid>https://dev.to/engberrg/mediatr-behaviors-to-validate-api-resource-existence-5c04</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F475%2F1%2AUGlyWoUBAwLEzJFPlz8fmQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F475%2F1%2AUGlyWoUBAwLEzJFPlz8fmQ.png"&gt;&lt;/a&gt;MediatR logo borrowed from &lt;a href="https://bit.ly/2N4Jz6S" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://bit.ly/2N4Jz6S" rel="noopener noreferrer"&gt;https://bit.ly/2N4Jz6S&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When building robust APIs it it really important with validation and descriptive error messages and status codes.&lt;/p&gt;

&lt;p&gt;In this post I am going to show you how you can get rid of duplicated code in your Request Handlers by adding MediatR behaviors to take care of validation for resource existence.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/jbogard/MediatR" rel="noopener noreferrer"&gt;MediatR&lt;/a&gt; is an in-process messaging library in .NET that supports requests/responses, commands, queries, events etc. Go check it out if you haven’t.&lt;/p&gt;

&lt;p&gt;In MediatR there is something called behaviors which allow you to build your own pipeline for requests. I use them for cross cutting concerns such as logging and validation of requests parameters.&lt;/p&gt;

&lt;p&gt;Recently when some endpoints were developed for a microservice I struggled with duplicated code in my Request Handlers that was necessary to have in place.&lt;/p&gt;

&lt;p&gt;To give you an example lets start with a couple of API endpoints, and also the implementation of the Request Handlers with the duplicated code.&lt;/p&gt;

&lt;p&gt;The endpoints in this example are:&lt;/p&gt;

&lt;p&gt;PUT /groups/{id}&lt;/p&gt;

&lt;p&gt;POST /groups/{id}/users&lt;/p&gt;

&lt;p&gt;The controller:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Both endpoints need to verify that the id-parameter actually matches a given group to be able to update a group / add user to a group (in my example I’m using EF Core as persistence, but you can safely ignore that).&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As you can see there is an if-check for group existence in both the handlers.&lt;/p&gt;

&lt;p&gt;How should we get rid of this duplication? Wouldn’t it be good to use some sort of “validation” here as a pre-step, so that the Request Handlers could look like this?&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Thank behaviors for that! Let’s introduce an interface that both the requests: UpdateGroupRequest and AddUserToGroupRequest implement.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Then create a behavior implementation class with generic constraint to the interface defined above so that the behavior only applies to requests implementing the IGroupRequest interface.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And a registration example using Autofac:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now we can rewrite our Request Handlers without the if statements, but still get the benefit of validation!&lt;/p&gt;

&lt;p&gt;Lets imagine we now add a couple of more endpoints:&lt;/p&gt;

&lt;p&gt;GET /groups/{id}&lt;/p&gt;

&lt;p&gt;POST /groups/{id}/permissions&lt;/p&gt;

&lt;p&gt;Add the IGroupRequest interface to your requests and you will get this feature out of the box. Pretty simple! I find this kind of approach really useful. What do you think?&lt;/p&gt;

&lt;p&gt;We have to keep in mind that there are both some cons and pros to this approach. What I’ve found out is:&lt;/p&gt;

&lt;h3&gt;
  
  
  Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Multiple roundtrips if you have a database that you validate the existence against.&lt;/li&gt;
&lt;li&gt;Validation as a separate class which might confuse some of the developers&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Cleaner code in the actual request handler&lt;/li&gt;
&lt;li&gt;No duplicated code scattered all over all Request Handlers that need to validate an entity’s existence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you liked this post. You know what to do! 👏&lt;/p&gt;




</description>
      <category>dotnet</category>
      <category>cleancode</category>
      <category>csharp</category>
      <category>api</category>
    </item>
    <item>
      <title>Apply the decorator pattern in .NET using Autofac</title>
      <dc:creator>Niklas Engberg</dc:creator>
      <pubDate>Tue, 06 Mar 2018 05:21:33 +0000</pubDate>
      <link>https://dev.to/engberrg/apply-the-decorator-pattern-in-net-using-autofac-gl3</link>
      <guid>https://dev.to/engberrg/apply-the-decorator-pattern-in-net-using-autofac-gl3</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5-6i416_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/960/1%2ACl1FLSzewuybqI18Gliv8w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5-6i416_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/960/1%2ACl1FLSzewuybqI18Gliv8w.png" alt=""&gt;&lt;/a&gt;Russian Dolls — metaphor to extend a given functions behavior. Photo borrowed from &lt;a href="http://maxpixel.freegreatpicture.com/Traditional-Russian-Toy-Russian-Doll-Russian-1090697"&gt;Maxpixel&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To follow good design principles and structure when you develop applications is something I advocate.&lt;/p&gt;

&lt;p&gt;As the development process goes on we add new functionality to our applications: it could be a feature request from your client or it could be improvements that you’ve suggested. No matter what, these upcoming changes will also change the already given codebase. When changes are introduced we want this to be as easy as possible.&lt;/p&gt;

&lt;p&gt;In this post I’m going to show you an example of how you can utilize the decorator pattern with the powerful IoC container &lt;a href="https://autofac.org/"&gt;Autofac&lt;/a&gt; in scenarios where you want to extend functionality to an existing feature.&lt;/p&gt;

&lt;p&gt;Lets say you are about to build a service that serves products. We will call this service &lt;strong&gt;IProductRepository&lt;/strong&gt; and for simplicity we only use one method called &lt;em&gt;GetById&lt;/em&gt;. It could look something like this with an implementation connected to it:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Normally you would register your concrete implementation XmlProductRepository as IProductRepository with the following code line to support the &lt;a href="https://en.wikipedia.org/wiki/Dependency_inversion_principle"&gt;&lt;em&gt;dependency inversion principle&lt;/em&gt;&lt;/a&gt;:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Lets say that you after a while need some logging when products are fetched. How do you accomplish this?&lt;/p&gt;

&lt;p&gt;It is tempting to just modify the implementation XmlProductRepository by injecting a logging service like this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;But that violates the &lt;a href="https://en.wikipedia.org/wiki/Open/closed_principle"&gt;open/closed principle&lt;/a&gt;. The principle states that you are not allowed to modify classes, but you can extend them. Here the decorator pattern is really handy.&lt;/p&gt;

&lt;p&gt;Instead of cluttering down your original implementation you &lt;em&gt;extend&lt;/em&gt; it by adding a logging proxy, and register it as a decorator of it.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;You will have to modify one code line though, and that one is the registration of the &lt;em&gt;original implementation&lt;/em&gt;. It will need to be a named registration now so we can refer to it when we register our decorator:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And then connect and register the decorator:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The key that we use to refer to the implementation here is &lt;em&gt;productRepository&lt;/em&gt;. When you have this code in place the first class that will be invoked when you inject your IProductRepository is the LoggingProductRepositoryProxy, and as we have injected the inner implementation to it it will just work as a proxy (russian doll style) following the open/closed principle.&lt;/p&gt;

&lt;p&gt;Lets say that you experience your XmlProductRepository slow and you need to cache your products for a while. How would you implement that? It is pretty easy to just add another decorator on top of your logging implementation:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Pretty flexible!&lt;/p&gt;

&lt;p&gt;The decorator pattern in really powerful when it comes to supporting &lt;em&gt;cross cutting concerns&lt;/em&gt; within applications.&lt;/p&gt;

&lt;p&gt;Did you find this post useful? You know what to do! 👏&lt;/p&gt;

&lt;p&gt;&lt;a href="https://goo.gl/w4Pbea"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EiHH_kD2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/700/1%2APZjwR1Nbluff5IMI6Y1T6g%402x.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;




</description>
      <category>programming</category>
      <category>technology</category>
      <category>coding</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Find your Circle of Competence — how to do well as a Software Architect</title>
      <dc:creator>Niklas Engberg</dc:creator>
      <pubDate>Sun, 04 Mar 2018 16:52:36 +0000</pubDate>
      <link>https://dev.to/engberrg/find-your-circle-of-competence--how-to-do-well-as-a-software-architect-oej</link>
      <guid>https://dev.to/engberrg/find-your-circle-of-competence--how-to-do-well-as-a-software-architect-oej</guid>
      <description>

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3tgWm_8y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/900/1%2AMf6uDnbuhhEwFtCaGc9edQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3tgWm_8y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/900/1%2AMf6uDnbuhhEwFtCaGc9edQ.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a Software Architect you are the link between requirements and implementation. It’s an ongoing challenge to make decisions that have a solid ground, decisions that enables future features to fit into an existing ecosystem that well aligns with good software principles such as SOLID, DRY, YAGNI to name a few.&lt;/p&gt;

&lt;p&gt;Building software requires constant improvement work. New type of technologies bubbles up every day and it is hard to keep you updated with everything that is happening. The more you learn, the more you realize how little you know, as the famous Socrates said. My experience of roughly 3–4 years as a Software Architect (by title, not if you ask me in person ;) has taught me to delimit myself into specific areas instead of jumping on everything that at first glance seems awesome and hot.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Circle of Competence
&lt;/h3&gt;

&lt;p&gt;I recently read about something called &lt;a href="http://www.businessinsider.com/the-circle-of-competence-theory-2013-12"&gt;the Circle of Competence&lt;/a&gt;. The Circle of Competence comes from one of the best investors, Warren Buffet, and is the subject area that matches a person’s skill or expertise. This principle originates from investing money within areas that you have a solid understanding in.&lt;/p&gt;

&lt;p&gt;The reason I’m mentioning the principle and why it caught my focus is that this kind of principle does not only apply to financial decisions, but really to everything. Including Software Development, and I’ve applied it.&lt;/p&gt;

&lt;p&gt;The more experienced you get, you realize that you can’t do everything &lt;em&gt;well&lt;/em&gt;. I don’t think this is anything new or spectacular but to zoom out and evaluate yourself and how you are doing is important. How do &lt;strong&gt;you&lt;/strong&gt; stay focused on the things that matters to you? I would love to hear!&lt;/p&gt;

&lt;h3&gt;
  
  
  The Circle of Competence applied
&lt;/h3&gt;

&lt;p&gt;In October last year I took the opportunity to join the financial industry as an architect / developer for a global bank. I previously worked in a similar role but in another industry so this was something completely new for me, business and company size-wise.&lt;/p&gt;

&lt;p&gt;My former job and company were ahead in many technical areas, but rarely had those challenging projects that enabled us techies to use our toolbox fully. That was one of the reasons I left. Anyway, that’s not the point here. :)&lt;/p&gt;

&lt;p&gt;The point is that when signing this new job, I knew that there’s going to be a lot of challenges such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;define visions and standards within the software area&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;set coding standards and best practices&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those challenges are quite wide and requires a lot of decisions to be made. How do you make sure you can accomplish those? I knew that I could benefit from my experience that worked out for us in my previous work to some extent but some kind of system would be great.&lt;/p&gt;

&lt;p&gt;Why not see how to use the principle Circle of Competence to my situation.&lt;/p&gt;

&lt;p&gt;Okay, so this is a picture of how the circle looks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZZmn6xiS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/899/1%2AKzho2XoBWDbXjjyxK1p4nw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZZmn6xiS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/899/1%2AKzho2XoBWDbXjjyxK1p4nw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But I think it is more accurate like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p28jsdsl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/899/1%2A_5PcRbI9m3Ze3yaZc3Uq1Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p28jsdsl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/899/1%2A_5PcRbI9m3Ze3yaZc3Uq1Q.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Split what you know into your comfort zone and what you don’t outside the zone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comfortable in&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Well, to start with I have mainly been focusing to back-end development and especially the .NET platform.&lt;/li&gt;
&lt;li&gt;I advocate test (TDD), have been working hard to apply clean code and good software principles etc. So within my Circle of Competence I can add this.&lt;/li&gt;
&lt;li&gt;I have experience in configuration build pipelines and continuous deployment.&lt;/li&gt;
&lt;li&gt;I am also quite good at communication and to transfer technical terms to non-technical people verbally. So to communicate those things should be doable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Not comfortable in&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What about networking, VIPs, bastion, firewall rules, DMZ and all this? Nah, I’m not really comfortable there.&lt;/li&gt;
&lt;li&gt;Core Banking Solutions? No.&lt;/li&gt;
&lt;li&gt;UX and front-end&lt;/li&gt;
&lt;li&gt;What about bank regulation and laws? Noo, not really, shivers…&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Okay, so that’s it. I’ve now divided what I know and what I don’t. This is roughly an overview and examples just to give you a hint of how I split things up. The list in reality is much longer and complex.&lt;/p&gt;

&lt;p&gt;By doing this little exercise I can then look back at the two challenges mentioned above and answer the question:&lt;/p&gt;

&lt;p&gt;How can I &lt;em&gt;define visions and standards within the software area&lt;/em&gt; and to &lt;em&gt;set coding standards and best practices&lt;/em&gt; given what I know and where I can contribute?&lt;/p&gt;

&lt;p&gt;If I look at the perspectives of the challenges with my confident zone in mind the probability that I will make good decisions increases than if I should start focusing on aspects outside the circle.&lt;/p&gt;

&lt;p&gt;Outside the circle, which are the areas you do know you are not an expert in, invite others to help you out, and accept that. Let them be the experts teaching you. This will help you expand your circle and hopefully you can expand others’. That is one of the philosophies I’m living after. It keeps me focused on the areas that I know I am good at.&lt;/p&gt;

&lt;p&gt;Note that this has nothing to do with what you want to learn but rather a method to keep you focused in the areas you know you can do well in.&lt;/p&gt;

&lt;p&gt;How do you stay focused as a Software Architect?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Did you like this article? You know what to do! 👏&lt;/em&gt;&lt;/p&gt;


</description>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>productivity</category>
      <category>selfimprovement</category>
    </item>
    <item>
      <title>Guidelines how I developed my personal skills (and helped others) by initiating a side project</title>
      <dc:creator>Niklas Engberg</dc:creator>
      <pubDate>Mon, 16 Jan 2017 16:57:36 +0000</pubDate>
      <link>https://dev.to/engberrg/guidelines-how-i-developed-my-personal-skills-and-helped-others-by-initiating-a-side-project-1da2</link>
      <guid>https://dev.to/engberrg/guidelines-how-i-developed-my-personal-skills-and-helped-others-by-initiating-a-side-project-1da2</guid>
      <description>&lt;p&gt;&lt;em&gt;This post is x-posted from Medium &lt;a href="https://hackernoon.com/guidelines-how-i-developed-my-personal-skills-and-helped-others-by-initiating-a-side-project-e1d93633681c?source=linkShare-827da1b55d18-1521572855" rel="noopener noreferrer"&gt;here&lt;/a&gt;. If you like the article, please feel free to give some applause and follow me! :)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A83VodhSSsT0kZs8aq6dklg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A83VodhSSsT0kZs8aq6dklg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every developer should have a side project I’ve heard. And yes, I can agree that it can be good for your personal career but it isn’t easy to get started with. If you are one feeling that, or if you are just interested in my story and how it became reality for me, please continue reading!&lt;/p&gt;

&lt;p&gt;I always try to improve my programming skills in the best possible way. As a developer you are solving problems most of the time of your day-to-day work. This problem solving tend to be tied to a specific stack or programming language that you are already familiar with.&lt;/p&gt;

&lt;p&gt;It is nothing bad about that but to broaden your skills outside your comfort zone you need to put in some extra effort, and that is hard. You can play around with hello world-examples and &lt;a href="http://www.codekatas.org/" rel="noopener noreferrer"&gt;coding katas&lt;/a&gt; but for me, it took me nowhere.&lt;/p&gt;

&lt;p&gt;I currently work at a digital agency as a developer and one day I identified a problem. Our company have invested well in health and wellness in form of a gym and instructor-led training activities such as Yoga, Pilates, Circuit Training and much more.&lt;/p&gt;

&lt;p&gt;A year ago (before my side project was born) to be able to participate in these occasions you had to sign up by communicating with our agency assistants. They then took notes for the participants. They kindly informed you back either: &lt;em&gt;yes, you have been enrolled / disenrolled&lt;/em&gt; or: &lt;em&gt;sorry, this occasion is full&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I noticed this process and started to think that there should be an application that replaced this work and that it would fit perfectly as a side project. And so it did. We now have a fully digitalized booking system for training activities!&lt;/p&gt;

&lt;p&gt;It’s been almost a year since I shipped the product and recently I evaluated my work and here I’m going to share my findings from this project, and what have been essential for getting things done.&lt;/p&gt;

&lt;h3&gt;
  
  
  Find a problem to solve
&lt;/h3&gt;

&lt;p&gt;What made sense to me was that my product would actually solve a problem. This gave me momentum and helped me motivate myself.&lt;/p&gt;

&lt;p&gt;This is probably the hardest one but it will make you commit. It does not have to be a big problem, it can basically be anything. If you are employed by a company, a recommendation would be to check with them. Do they feel the absence of any technical product / tool that can help them? Ask!&lt;/p&gt;

&lt;p&gt;Github with it’s open source culture is full of different projects that need contributors. Check out &lt;a href="http://up-for-grabs.net/" rel="noopener noreferrer"&gt;Up For Grabs&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Nothing is perfect
&lt;/h3&gt;

&lt;p&gt;For the product that I built I started to think big, wondered, and felt that I needed to deliver something that was perfect.&lt;/p&gt;

&lt;p&gt;Let’s face it, your work will never be perfect. At some point you just have to ignore that when starting a new project. We would all love the perfect idea that no one have ever thought of or implemented yet, but there is no such idea. This is something that I’ve learnt throughout the process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keep it simple, don’t get lost in details
&lt;/h3&gt;

&lt;p&gt;In my case with the booking application I decided to start off really simple: to initially replace the manual work by implementing an easy web interface. All other features would have been improvements (since nothing existed at this point). I just needed to keep telling myself that. And when I finally got comfortable about it, I started to become productive.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Side note: The application has been running for almost a year now and no one has ever complained about the minimalistic user interface I initially shipped. Why? Because the application does what it should and doesn’t need a fancy UI.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  It’s just a matter of execution
&lt;/h3&gt;

&lt;p&gt;I’ve seen ideas that just remains as ideas, and never really turns into something tangible. My recommendation is that if you believe in something, you should just go for it! Make a plan.&lt;/p&gt;

&lt;p&gt;This goes hand in hand with keeping it simple. If you cannot manage to get your product up and running pretty soon, it will probably start to decay.&lt;/p&gt;

&lt;p&gt;Start with the simplest solution of the problem you are facing. Ship a minimum viable product that fairly soon hits the market. This will give you an early response to your work.&lt;/p&gt;

&lt;h3&gt;
  
  
  Evaluate your work and be proud!
&lt;/h3&gt;

&lt;p&gt;What I never did until recently was to look back and analyze my work. What have I actually delivered? Learnings? Could I have done anything differently? These questions are good to ask yourself.&lt;/p&gt;

&lt;p&gt;Besides the findings that I’ve presented this project has taught me a new programming language and how to organize my work. And as the headline for this post states it has also made a huge impact on the employees since they easily themselves can manage training activities. So, check on that :)&lt;/p&gt;

&lt;p&gt;I try to keep it as a habit to continuously improving the product as much as I can. And it is a lot easier now since the product is being used by others, so I get their input and their ideas for free— which in turn generates more work :)&lt;/p&gt;

&lt;p&gt;I would love to hear your thoughts. What have worked out for you?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you are interested in details about what technical products I used for this application I might write a more technical post about that :)&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>coding</category>
      <category>selfimprovement</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
