<?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: Andrew Cahill</title>
    <description>The latest articles on DEV Community by Andrew Cahill (@andrewcahill).</description>
    <link>https://dev.to/andrewcahill</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%2F587930%2F397675c2-ff94-4a8b-bee6-ff4cfad94ab6.jpeg</url>
      <title>DEV Community: Andrew Cahill</title>
      <link>https://dev.to/andrewcahill</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andrewcahill"/>
    <language>en</language>
    <item>
      <title>Are We Really Doing Continuous Integration?</title>
      <dc:creator>Andrew Cahill</dc:creator>
      <pubDate>Sun, 28 Feb 2021 16:50:32 +0000</pubDate>
      <link>https://dev.to/andrewcahill/are-we-really-doing-continuous-integration-430g</link>
      <guid>https://dev.to/andrewcahill/are-we-really-doing-continuous-integration-430g</guid>
      <description>&lt;p&gt;&lt;strong&gt;Preamble&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After seeing some recent tweets and blog posts by Martin Fowler and Kief Morris on the topics of Continuous Integration, Pull request reviews and branching and how we may not be doing it quite right at least internally within an organization(references below), led me to explore this practice a little further.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First, let’s define what Continuous Integration is&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Continuous Integration is the practice of merging all developers working copies to a shared mainline daily if not multiple times a day.&lt;/p&gt;

&lt;p&gt;I really like this idea as it brings with it very clear benefits including&lt;/p&gt;

&lt;p&gt;– reducing the possibility of large merge conflicts&lt;/p&gt;

&lt;p&gt;– reduces peer review effort as the code to review is smaller and thus easier to reason about&lt;/p&gt;

&lt;p&gt;– smaller commits make it easier to find issues and roll back if necessary&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A little background&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have been a proponent of feature branching and pull request review ahead of merging(pre-integration review) within an organization’s team for some time. The reasons are as follows: &lt;/p&gt;

&lt;p&gt;Feature branching allows the reviewers to review a PR that encompasses the entire body of work that is aligned to a feature enabling them to know the scope of work associated. &lt;/p&gt;

&lt;p&gt;Pre-integration reviews provide value in decreasing potential issues that otherwise would not have been caught by say unit, integration, functional tests and analysis, this is especially true if the codebase is a brownfield project that may not already contain a high level of test coverage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Issues&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;However, we noticed quite early on that there were some drawbacks to these practices such as:&lt;/p&gt;

&lt;p&gt;Feature branches required an entire feature to be completed before a PR be created, well if a feature required several days to complete this right away violated the CI principle and thus does not bring with it the benefits above. &lt;/p&gt;

&lt;p&gt;Pre-integration reviews incurred delays in completing tasks due to relying on team members being available to perform this review at the time of task completion, as team members were typically busy completing their own tasks we typically waited for them to complete their tasks to avoid them context switching unless there was a dependency on this task. So this meant the developer who completed the task would pick up a new feature to switch to and wait for the reviewer to be free, which may be when they develop in this case is now busy so no matter which way you went there was a hit on throughput/productivity and led to tasks taking many days to complete again violating CI.&lt;/p&gt;

&lt;p&gt;As you can see these practices may not be the most effective way of going about doing things especially as speed is of priority which almost always is the case.&lt;/p&gt;

&lt;p&gt;One exception to this where such a level of rigour may be required for compliance reasons.&lt;/p&gt;

&lt;p&gt;So with feature branches and pre-integration review causing such issues I was curious about solutions to these problems or if these were simply a trade-off to accept for apparent higher quality. After reading further into the aforementioned blog posts there were a few good thoughts that made me rethink my ideas around quality oversight.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Possible solutions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, I think we have to look at how we may have got to perform such practices -&amp;gt; Open Source.&lt;/p&gt;

&lt;p&gt;Pre-integration review and feature branches make complete sense for open source development as you are working with external contributors who may not have the same standards, styles and objectives as you, wherein an organization it would be assumed this would not be the case.&lt;/p&gt;

&lt;p&gt;So what are the alternatives to these practices in an organization setting? &lt;/p&gt;

&lt;p&gt;Instead of performing pre-integration reviews, we could apply pair programming or periodic code reviews:&lt;/p&gt;

&lt;p&gt;Pair programming, one of the practices in XP, suggesting 2 programmers work on a task together one acting as a developer and another acting as a reviewer in real-time reducing the time of developing something incorrectly and re-implementing. Shortening the development – review – improve cycle&lt;/p&gt;

&lt;p&gt;Periodic reviews where you can perform scheduled reviews of committed code, this takes an assumption that code committed is of a reasonable quality to be committed through training etc. and if there are issues they can be fixed through subsequent refactoring.&lt;/p&gt;

&lt;p&gt;Instead of creating feature branches we could allow partially completed features to the codebase. This way you can push your changes as frequently as you like and be able to adhere to the CI principle or merging at least once per day. A side benefit of performing this rapid commit style is that it encourages refactoring, and following a clean as you go mindset. What I mean is that you can make any refactoring you notice during your development whether it’s part of the feature you are working on or not. &lt;/p&gt;

&lt;p&gt;You might say well how do I do this as it will not be a fully working feature and we can’t release partial features to end users, well one popular approach to get around this exact issue is to begin using feature flags and switch on this feature &amp;amp; make it visible when ready.&lt;/p&gt;

&lt;p&gt;Performing refactoring like this is a safer approach for two reasons, one is that it provides you with a better chance of getting to fixing an issue sooner rather than later before complexity increases or it becomes a more serious issue down the line and two hoping to get time at a later time to apply refactoring is a big challenge get buy-in as delivering features pressures will always be present and this is a good thing as we don't really want things to get quiet do we!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Again the above is not to say one way is necessarily better than the other, depending on your circumstances one way may be more appropriate than the other. This post is just to provide further options if you find yourself in a similar situation where such processes may be hampering your delivery velocity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://infrastructure-as-code.com/book/2021/01/02/pull-requests.html"&gt;https://infrastructure-as-code.com/book/2021/01/02/pull-requests.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://martinfowler.com/bliki/RefinementCodeReview.html"&gt;https://martinfowler.com/bliki/RefinementCodeReview.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://martinfowler.com/bliki/PullRequest.html"&gt;https://martinfowler.com/bliki/PullRequest.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://martinfowler.com/articles/branching-patterns.html"&gt;https://martinfowler.com/articles/branching-patterns.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>devops</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Adding resilience to my http calls using Polly</title>
      <dc:creator>Andrew Cahill</dc:creator>
      <pubDate>Sun, 31 Mar 2019 20:26:41 +0000</pubDate>
      <link>https://dev.to/andrewcahill/adding-resilience-to-my-http-calls-using-polly-2o6</link>
      <guid>https://dev.to/andrewcahill/adding-resilience-to-my-http-calls-using-polly-2o6</guid>
      <description>&lt;p&gt;As I am building out my MyReverie(&lt;a href="https://github.com/andrewcahill/myreverie"&gt;https://github.com/andrewcahill/myreverie&lt;/a&gt;) project in GitHub, I wanted to add some resilience to my http calls. I had heard of the Polly framework that made doing this extremely easily.&lt;/p&gt;

&lt;p&gt;Polly is an open source framework that provides resilience capabilities on transient errors that you can leverage in your own applications thus removing the burden of having to write this code out manually yourself. Types of capabilities include Retry, Circuit Breaker, Fallback among others.&lt;/p&gt;

&lt;p&gt;If you were to try write this code yourself and for it to be done correctly can be a little tricky and error prone due to inconsistencies that may develop over time as these are cross cutting concerns it should be abstracted to a library to be reused – so why reinvent the wheel!&lt;/p&gt;

&lt;p&gt;Type of resilience’s you may want to consider could be against network outages or systems being busy attending to other work, this is particularly important in larger microservice applications that rely heavily on intercommunication of services so instead of timing out or returning with an error wouldn’t you like it to retry and handle this scenario a little more elegantly and smarter.&lt;/p&gt;

&lt;p&gt;For my purposes I wanted to simply add an ability that if the endpoint was for some reason unavailable that it would ‘Retry’ a certain number of times and not simply fail after the first attempt. It is a simple use case but it allowed me to easily become familiar with this framework.&lt;/p&gt;

&lt;p&gt;To get Polly up and running is quite straight forward.&lt;/p&gt;

&lt;p&gt;In my startup class I define the http client&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services.AddHttpClient("api").AddTransientHttpErrorPolicy(p =&amp;gt; p.RetryAsync(5));

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

&lt;/div&gt;



&lt;p&gt;This effectively means to retry the http call five time before returning with a failure response. I chose 5 as a reasonable amount of times to retry but you can choose whichever number you wish.&lt;/p&gt;

&lt;p&gt;I need to of course add the Polly package(in my case I am using v2.2.0):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Microsoft.Extensions.Http.Polly

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

&lt;/div&gt;



&lt;p&gt;add then add the using statement&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Polly;

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

&lt;/div&gt;



&lt;p&gt;In my service class within my web project where I make my http calls to the API I inject ‘IHttpClientFactory’ using Dependancy Injection which comes out of the box with .Net Core as a constructor parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IHttpClientFactory httpClientFactory

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

&lt;/div&gt;



&lt;p&gt;I then assign this parameter to a global variable ‘_httpClientFactory’ in the constructor as below&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;I initialize a new HttpClient object to the client I defined in the startup class by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HttpClient client = _httpClientFactory.CreateClient("api");

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

&lt;/div&gt;



&lt;p&gt;after which I make the http calls as you would normally do, but this time incorporating using Polly.&lt;/p&gt;

&lt;p&gt;In my case it is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await client.GetStringAsync(_appSettings.GoalsUrl);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if this http call fails it will try another four times before returning to the caller thus improving the resilience of my system in case of intermittent connectivity issues!.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://aviddeveloper.com/adding-resilience-to-http-calls-with-polly/"&gt;Adding resilience to my http calls using Polly&lt;/a&gt; appeared first on &lt;a href="https://aviddeveloper.com"&gt;Avid Developer&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>dotnetcore</category>
      <category>aspnetcore</category>
      <category>c</category>
      <category>polly</category>
    </item>
    <item>
      <title>My Git Command Line Toolbelt</title>
      <dc:creator>Andrew Cahill</dc:creator>
      <pubDate>Thu, 18 Oct 2018 18:22:36 +0000</pubDate>
      <link>https://dev.to/andrewcahill/my-git-command-line-toolbelt-889</link>
      <guid>https://dev.to/andrewcahill/my-git-command-line-toolbelt-889</guid>
      <description>&lt;p&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lately I have been getting a little more familiar with the Git command line and I have to say I am liking it. The reason why I had stayed away from it until now was that I found the GUI(SourceTree in my case) to be a safe/easier interactive medium for something I was not at all that familiar with. However I realize the CLI is faster for issuing commands so I made a conscious effort to start familiarizing myself with it.&lt;/p&gt;

&lt;p&gt;The idea of this post was to demonstrate and explain the most frequent commands I typically use and will hopefully help others interested in understanding the Git CLI basics but may be a little apprehensive.&lt;/p&gt;

&lt;p&gt;I will demo operations from both a repository owner as well as a repository contributor perspective.&lt;/p&gt;

&lt;p&gt;Disclaimer: I know there are many more commands that I am excluding however I just wanted to focus on what I believe are the most frequent most used day to day commands for a beginner.&lt;/p&gt;

&lt;p&gt;I wanted to not only list the commands with their explanations but provide a real example against a sample application for better context.&lt;/p&gt;

&lt;p&gt;To follow these examples, you will need to have some pre-requisites installed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pre-requisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Git installed on your machine – you can download from here: &lt;a href="https://git-scm.com/downloads"&gt;https://git-scm.com/downloads&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You have the .Net Core SDK installed(as I will be demonstrating these command on a sample .Net Core application – if you do not have it you can browse to : &lt;a href="https://www.microsoft.com/net/download"&gt;https://www.microsoft.com/net/download&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What I use (in case you were wondering from the images)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PoshGit – nice PowerShell module to allow me to see git status from the prompt(&lt;a href="https://github.com/dahlbyk/posh-git"&gt;https://github.com/dahlbyk/posh-git&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;PowerShell through command line – easier to see command colors in black background&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What I will cover&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I will list the commands with their explanations, then apply them on a sample application which I will build completely from scratch using .Net Core.&lt;/p&gt;

&lt;p&gt;I will be 100% in the command line from creating the application to interacting with Git outside of using an editor to update files.&lt;/p&gt;

&lt;p&gt;The .Net Core application that I will create will be a simple console application to keep things as light as possible and focus on Git rather the application itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Commands I will be using:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Git Config
This command is to set your initial one-time configuration, I will use it to set my Identity (Name and Email).
Note: You can set either global or project specific configuration, meaning the scope at which the configuration takes affect. I will apply it to the new project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;If you want to set the configuration globally you simply add the ‘—global’ switch.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Git Init&lt;br&gt;&lt;br&gt;
This initializes our new project directory to be a git repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Git Add&lt;br&gt;&lt;br&gt;
This command adds your files from your working directory to staging or to the git Index to be committed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Git Status&lt;br&gt;&lt;br&gt;
This allow us to view the files which have been updated, added or deleted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Git Commit&lt;br&gt;&lt;br&gt;
This command commits your changes ready to be pushed to your repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;You add the -m switch to attach a message to your commit.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tip: You can bypass the add command above and combine the add command to the commit command as one single command by adding the ‘-am’&lt;/em&gt;  switch –&amp;gt; I will demonstrate below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Git Push&lt;br&gt;&lt;br&gt;
Pushes committed changes to your remote repository(GitHub in our case)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Git Checkout&lt;br&gt;&lt;br&gt;
Allows you to switch to a different branch, you can also add the ‘-b’ switch to create a new branch based off your current branch –&amp;gt; I will demonstrate below.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Git Diff&lt;br&gt;&lt;br&gt;
Finds differences between of files before and after changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Git Merge&lt;br&gt;&lt;br&gt;
Merges changes from one branch to another.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Git Stash&lt;br&gt;&lt;br&gt;
This command allows you to store away changes that you may not want to apply right away.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Git Clone&lt;br&gt;&lt;br&gt;
Clones from a remote repository to a local repository&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Git Pull&lt;br&gt;&lt;br&gt;
Pull all the latest changes that may have been applied on your remote repository and applies them to your local repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Okay, let’s begin&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, we need to create our .Net Core Console application to work with.&lt;/p&gt;

&lt;p&gt;Open up PowerShell, I will open it within the command prompt – by simply typing ‘PowerShell’ within the command prompt – and you will see below that PowerShell is listed on the top bar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-7.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I-L1fL5b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-6.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next just browse to a directory in which you want to create the new project, in my case I will create in ‘c:\dev\github’.&lt;/p&gt;

&lt;p&gt;Now create the application and name it ‘GitCommandLine’ by typing  -&amp;gt;&lt;/p&gt;

&lt;p&gt;‘dotnet new console -n GitCommandLine’.&lt;/p&gt;

&lt;p&gt;You should see the below..&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-8.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uYE67t4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-7.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our dotnet core console app created, now let’s start with Git.&lt;/p&gt;

&lt;p&gt;First, Lets’ navigate in to our project directory we just created.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Init&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we want to initialize our new project as a Git repository so we will want to use the ‘Git Init’ command like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-9.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K--q5_1h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-8.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Config&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we want to set the config specifically the Identity (user name and email) to associate with our commits, I will use&lt;/p&gt;

&lt;p&gt;User name: John Doe&lt;br&gt;&lt;br&gt;
Email address: &lt;a href="mailto:john@johndoe.com"&gt;john@johndoe.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: The configuration scope is just this project so I excluded the –global switch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-10.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MnrqPtHA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-9.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Config –l&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Let’s view the current configuration to confirm out setting for applied correctly by issuing the ‘git config –l command’&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-11.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N89ODolp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-10.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and it looks like they did as you can see near the bottom.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Status&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s call a Git status to see the current changes in our repository.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-12.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vQdaT0Tz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-11.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What this is telling us is that we have not specified any files to be included in the next commit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Add&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As mentioned above we can either call a Git add as a separate command or within the commit command, let’s call it separately for now.&lt;/p&gt;

&lt;p&gt;Here we specify what is to be added to staging, we are adding everything with ‘git add .’ we could have specified individual files if we wanted to.&lt;/p&gt;

&lt;p&gt;Now let’s rerun our git status after applying the git add command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-13.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5_nESqAU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-12.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will now see the output is different – stating we have new files ready to be committed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Commit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s go ahead and commit them, we will add a message to our commit let’s call it ‘Initial commit’&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-14.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QXhvtuQu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-13.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Push&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we will want to push our local repository changes to our remote repository (GitHub).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;FYI: I have already created a new repository in my GitHub account(&lt;a href="https://github.com/andrewcahill/GitCommandLine"&gt;https://github.com/andrewcahill/GitCommandLine&lt;/a&gt;).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In order to push I will need to specify my remote repository details, specifically where it is located so I use the below command.&lt;/p&gt;

&lt;p&gt;‘git remote add origin &lt;a href="https://github.com/andrewcahill/GitCommandLine.git%E2%80%99"&gt;https://github.com/andrewcahill/GitCommandLine.git’&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-15.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oaynB8Mm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-14.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we will issue a push command with ‘git push -u origin master’.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-16.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tETJUg8---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-15.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great, now we have our repository in GitHub.&lt;/p&gt;

&lt;p&gt;Now let’s create a new development branch, make some changes in this new branch then push them to GitHub and then finally merge these changes to master.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Checkout&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will use the ‘-b’ switch to specify a new branch and call the new branch “development”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-17.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oUn596U6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-16.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will make a minor change to our Program.cs file and change the “Hello world!” output to “Hello GitHub!”&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Quick tip: To view content of a file there is a PowerShell command ‘Get-Content’ which will allow you to do exactly that.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We can use this to view a before and after, like below..&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-18.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KCOG5H4m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-17.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And after the change..&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-19.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yA9s__0b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-18.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Diff&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can use ‘Git diff’ to view the changes that will be applied on our next commit&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-20.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BOUY1OPL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-19.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s commit them, why not this time add our ‘add’ command within our commit command and add the message “Updated output”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-21.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nH3TiMfa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-20.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s push our changes to a new remote ‘development’ branch. In order to do this we will want to create our new remote branch by issuing the command ‘git push –set-upstream origin development’&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note  this is only a one-time operation&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Merge&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let’s merge these development changes to master so both are in sync.&lt;/p&gt;

&lt;p&gt;This is a two-step process first lets checkout or switch to our master branch then we will call merge – like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-22.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XID_Uo3g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-21.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can see the master branch has an update pending so let’s push this change to our remote repository.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-23.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--10jmvFhD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-22.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it, well at least from the point of view of the creator of the repository, what about the point of view of a contributor, they may want to make contributions to your repository. In this case the process is quite straight forward.&lt;/p&gt;

&lt;p&gt;All we really need to do is clone down this repository, to a directory of our choosing, make the changes and push them back up.&lt;/p&gt;

&lt;p&gt;Let’s do that..&lt;/p&gt;

&lt;p&gt;I will create a new folder under my github directory called ‘GitCommandLineContributor’.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Clone&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let’s navigate in to our new directory and clone using ‘git clone &lt;a href="https://github.com/andrewcahill/GitCommandLine.git%E2%80%99"&gt;https://github.com/andrewcahill/GitCommandLine.git’&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-24.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7K4up_KR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-23.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Typically changes are done within either the development or feature branches so let’s switch to the development branch here, by issuing ‘git checkout development’.&lt;/p&gt;

&lt;p&gt;Now as a contributor lets make another change to the Program.cs file –&amp;gt; we will change from “Hello GitHub” to “Hello from contributor”.&lt;/p&gt;

&lt;p&gt;Okay, now let’s go ahead and commit and push as before.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-25.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OeXvn-AW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-24.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Pull&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now go back to our owner viewpoint(c:\dev\github\gitcommandline) in my case, switch to development and pull down any changes that may have happened by contributors by issuing ‘git pull‘.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-26.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2JG02mXx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-25.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And we see after we perform a pull we can see new changes being applied.&lt;/p&gt;

&lt;p&gt;Now let’s merge these contributor changes to master.&lt;/p&gt;

&lt;p&gt;So we issue ‘git checkout master’ &amp;amp; ‘git merge development’ and finally ‘git push’ as before.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-27.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nUPCHMCZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-26.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git –Help&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At any point you can run a ‘git –help’ command which lists all the available git commands available to run. As well as that you can run a ;git [command] –help; to bring up a webpage detailing further information on that specific command. For example ‘git commit –help’ –&amp;gt; pretty cool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git Stash&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally one last command I wanted to show was the Git Stash command, as I have on more than one occasion forgotten to switch to the correct branch before making changes, for example accidentally making changes on master instead of development – this command really helps me out. As I usually try to make my commits small and often I had previously ended up simply copying my changes to the new branch –&amp;gt; a pain and error prone.&lt;/p&gt;

&lt;p&gt;How I will show it is:&lt;/p&gt;

&lt;p&gt;As an example we accidentally make a change to master that we wanted to make to development so we  stash these changes, switch to the correct branch(development) and apply the changes to the development branch.&lt;/p&gt;

&lt;p&gt;First make sure we are in the master branch by running ‘git status’&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-28.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xcFZptOd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-27.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets again make a change to our Program.cs file with “Hello owner!” in our output.&lt;/p&gt;

&lt;p&gt;Again let’s confirm our changes..&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-29.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V0tgYn7Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-28.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we realize this change should have been in development, so, lets stash these changes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-30.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v8KJAcTM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-29.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Checkout development and run ‘git stash apply’.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-31.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zLUhG-If--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-30.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now perform the same steps again(git commit with add – git push – git checkout master – git merge development &amp;amp; finally git push) as below..&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/10/image-32.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_Y3s42dx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/10/image_thumb-31.png" alt="image" title="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That’s it a top to bottom of all my frequent Git commands, I hope somebody may find this overview useful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For further information on Git commands, explanations etc. check out: &lt;a href="https://git-scm.com/"&gt;https://git-scm.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://aviddeveloper.com/my-git-command-line-toolbelt/"&gt;My Git Command Line Toolbelt&lt;/a&gt; appeared first on &lt;a href="https://aviddeveloper.com"&gt;Avid Developer&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>netcore</category>
      <category>git</category>
    </item>
    <item>
      <title>Adding Tiered Compilation in .Net Core 2.1</title>
      <dc:creator>Andrew Cahill</dc:creator>
      <pubDate>Mon, 03 Sep 2018 09:03:56 +0000</pubDate>
      <link>https://dev.to/andrewcahill/adding-tiered-compilation-in-net-core-2-1-325j</link>
      <guid>https://dev.to/andrewcahill/adding-tiered-compilation-in-net-core-2-1-325j</guid>
      <description>&lt;p&gt;One of the many great features of .Net Core is its performance, which it certainly excels at.&lt;/p&gt;

&lt;p&gt;A few weeks back I seen a new performance feature, well preview feature in .Net Core 2.1 – called “Tiered compilation”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is it&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well you could say at its core in enables applications to not only start faster but also run faster. It has a lot to do with the JIT( &lt;strong&gt;J&lt;/strong&gt; ust &lt;strong&gt;I&lt;/strong&gt; n &lt;strong&gt;T&lt;/strong&gt; ime) compilation process – first let me explain a little about JIT.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JIT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Leaving aside AOT compilation for now, The .Net CLR typically uses the JIT compiler to compile the MSIL against the CLR using CIL metadata to machine native code for the target machines architecture.&lt;/p&gt;

&lt;p&gt;It performs this process either on startup with full assembly compilation when its loaded or on demand at runtime when a particular method is called – what happens here is basically that when a method is called first time it gets JIT compiled then on subsequent calls the calling code effectively just references the native/Jitted version of the method in memory.&lt;/p&gt;

&lt;p&gt;Typically in JIT each method would be JIT compiled once either using aggressive optimization on startup sacrificing startup time but benefitting from steady state runtime performance, or simple optimization at the start sacrificing steady state performance throughout runtime.  There was typically only a single choice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Back to tiered compilation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With tiered compilation you can JIT compile the same method more than once to  produce a more optimized version depending on its usage, it is hot swapped at runtime automatically for you making the decision for you.&lt;/p&gt;

&lt;p&gt;On startup it performs a basic compilation(tier 0) but if the method gets used frequently the method is recompiled on  the background thread to produce a more optimized version(tier 1) for you to improve the runtime performance. This is sometime termed called adaptive optimization.&lt;/p&gt;

&lt;p&gt;This in effect produces both fast startup and fast steady state performance.&lt;/p&gt;

&lt;p&gt;Another benefit of tiered compilations is faster steady state with applications that use precompiled images shipped with the framework code of .net core, with tiered compilation it can produce more  optimized versions of the code at runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In order to try it out for yourself, there are a few options&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Assumes you have access to or are building the source code, then it is a trivial change to your csproj file by simply adding the MSBuild property :&lt;/li&gt;
&lt;/ol&gt;


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


&lt;p&gt;like below&lt;/p&gt;


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


&lt;ol&gt;
&lt;li&gt;If the app was previously built and you have no access to the source code but you have access to the appsettings file simply add&lt;/li&gt;
&lt;/ol&gt;


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


&lt;p&gt;to the configProperties.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;


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


&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can check out official Microsoft article here: &lt;a href="https://blogs.msdn.microsoft.com/dotnet/2018/08/02/tiered-compilation-preview-in-net-core-2-1/"&gt;Tiered Compilation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Check out the GitHub thread indicating performance comparisons of Tiered vs non-tiered apps : &lt;a href="https://github.com/dotnet/coreclr/issues/18361#issuecomment-396402549"&gt;GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://aviddeveloper.com/tiered-compilation-in-net-core-2-1/"&gt;Adding Tiered Compilation in .Net Core 2.1&lt;/a&gt; appeared first on &lt;a href="https://aviddeveloper.com"&gt;Avid Developer&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>netcore</category>
    </item>
    <item>
      <title>Add versioning to an Asp.Net Core Web API</title>
      <dc:creator>Andrew Cahill</dc:creator>
      <pubDate>Fri, 13 Jul 2018 05:11:40 +0000</pubDate>
      <link>https://dev.to/andrewcahill/add-versioning-to-an-asp-net-core-web-api-4blb</link>
      <guid>https://dev.to/andrewcahill/add-versioning-to-an-asp-net-core-web-api-4blb</guid>
      <description>&lt;p&gt;There are occasions you would like or need to add versioning to your API in order to specify availability or non-availability of functionality.&lt;/p&gt;

&lt;p&gt;There are a few options available such as Query String, Url based as well as Http header.&lt;/p&gt;

&lt;p&gt;For my purposes I am going to talk about the Url based approach, as I have implemented this option in my &lt;a href="https://github.com/andrewcahill/MyReverie"&gt;MyReverie&lt;/a&gt; repo due to a matter of preference of being cleaner and more explicit.&lt;/p&gt;

&lt;p&gt;First things first we will need to go ahead and install the Nuget package:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Microsoft.AspNetCore.Mvc.Versioning&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Within the Startup class ConfigureServices method add the below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services.AddApiVersioning(v =&amp;gt;
{
    v.ReportApiVersions = true;
    v.AssumeDefaultVersionWhenUnspecified = true;
    v.DefaultApiVersion = new ApiVersion(1, 0);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above three properties are particularly useful in that they allow default versions to be set if none are explicitly set as well as providing header information on versioning that are supported.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ReportApiVersions&lt;/strong&gt; : we are requesting the header to respond with supported API versions&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AssumeDefaultVersionWhenUnspecified&lt;/strong&gt; : set the default version if none are explicitly requested&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DefaultApiVersion&lt;/strong&gt; : Set the default version to 1.0 if default is used&lt;/p&gt;

&lt;p&gt;To better illustrate the first property above see below. I used Postman to see the response header with supported versions listed, which I highlighted&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/07/Versioning_thumb7.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JuYxaX6U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/07/Versioning_thumb7_thumb.png" alt="Versioning_thumb7" title="Versioning\_thumb7"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now all I have to do is simply add and update the controller attribute in my case&lt;/p&gt;

&lt;p&gt;At the moment as I am still on version 1, I will add the attribute&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ApiVersion("1.0")]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and update the route attribute like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Route("api/{v:apiVersion}/[controller]")]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the result of the Controller class(GoalsController in my case) attributes should look like the below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/07/Versioning_thumb1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q11y2z1J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/07/Versioning_thumb1_thumb.png" alt="Versioning_thumb1" title="Versioning\_thumb1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s test our F5 and browse to our API endpoint with suffix : /api/1.0/goals, in my case below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aviddeveloper.com/wp-content/uploads/2018/07/Versioning_thumb3.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wh7R9uF1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://aviddeveloper.com/wp-content/uploads/2018/07/Versioning_thumb3_thumb.png" alt="Versioning_thumb3" title="Versioning\_thumb3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it my API is now versioned v1.0&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://aviddeveloper.com/versioning-asp-net-core-web-api/"&gt;Add versioning to an Asp.Net Core Web API&lt;/a&gt; appeared first on &lt;a href="https://aviddeveloper.com"&gt;Avid Developer&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>aspnetcore</category>
      <category>c</category>
      <category>versioning</category>
      <category>webapi</category>
    </item>
  </channel>
</rss>
