<?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: Barranger Ridler</title>
    <description>The latest articles on DEV Community by Barranger Ridler (@barranger).</description>
    <link>https://dev.to/barranger</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%2F154575%2F8022ce95-f6b8-4d95-943b-5ad73967ce6c.jpeg</url>
      <title>DEV Community: Barranger Ridler</title>
      <link>https://dev.to/barranger</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/barranger"/>
    <language>en</language>
    <item>
      <title>How to start building a weather app in React Native</title>
      <dc:creator>Barranger Ridler</dc:creator>
      <pubDate>Tue, 01 Sep 2020 16:31:43 +0000</pubDate>
      <link>https://dev.to/barranger/how-to-start-building-a-weather-app-in-react-native-2n3i</link>
      <guid>https://dev.to/barranger/how-to-start-building-a-weather-app-in-react-native-2n3i</guid>
      <description>&lt;p&gt;Finally was able to get back to pumping out some blog entries.  Here's the first output of that effort:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7YjZvNZD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://assets.website-files.com/5e0254b18d72cc3b908a8a38/5f47d2fb22e0fa386d146030_current_weather%2520%281%29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7YjZvNZD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://assets.website-files.com/5e0254b18d72cc3b908a8a38/5f47d2fb22e0fa386d146030_current_weather%2520%281%29.png" alt="starter weather app in React Native"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.redbitdev.com/post/react-native-weather-app-how-to"&gt;Here's the accompanying blog post&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>tutorial</category>
      <category>howto</category>
    </item>
    <item>
      <title>IE is caching your function</title>
      <dc:creator>Barranger Ridler</dc:creator>
      <pubDate>Wed, 22 Jan 2020 08:46:37 +0000</pubDate>
      <link>https://dev.to/barranger/ie-is-caching-your-function-55nf</link>
      <guid>https://dev.to/barranger/ie-is-caching-your-function-55nf</guid>
      <description>&lt;p&gt;Hi my name is Barranger, and I hate Internet Explorer.&lt;/p&gt;

&lt;p&gt;Now that we have that out of the way, let me describe to you the 2345678th reason for this hatred, by explaining what IE is doing with requests to your fancy new &lt;code&gt;HttpTrigger&lt;/code&gt;-ed Azure Function (a waaaaaay less fancy function we'll use for this post &lt;a href="https://github.com/barranger/iecache"&gt;can be found here&lt;/a&gt;): it's caching the response, even though we have not set the caching header.&lt;/p&gt;

&lt;p&gt;If you look at the source code at the link you'll see I've created both a simple Azure Function as well as an extremely simple html file that will invoke the function, when they're both running it will look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hITxY1_p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://barranger.dev/static/9dbdec56d9d25e3629ebf9ce74199fe7/9fff5/Screenshot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hITxY1_p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://barranger.dev/static/9dbdec56d9d25e3629ebf9ce74199fe7/9fff5/Screenshot.png" alt="Screenshot"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;em&gt;(please stop with all the offers for my design work, I know it's beautiful)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you click the refresh button over and over again you'll see that it updates as you'd expect in both Chrome and Firefox.  If you try it in IE however, it will always stay the same, and a quick peak at the developer tools will show you why:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uv_56qUD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://barranger.dev/static/a8e9e72c5729f23c0f6bc475e75cb45e/5200b/CachedResponse.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uv_56qUD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://barranger.dev/static/a8e9e72c5729f23c0f6bc475e75cb45e/5200b/CachedResponse.png" alt="Cached Response"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's right! Even though no caching headers have been found, IE has decided that it's going to cache the value and just reuse it every time.  &lt;/p&gt;

&lt;p&gt;Luckily there's a pretty easy fix for this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HttpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Cache-Control"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"no-cache"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;... in your &lt;code&gt;HttpTrigger&lt;/code&gt;-ed function and you've removed one of the many issues that IE will cause you:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZC7OOA6i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://barranger.dev/static/d8ed9364d09b9cc036b1fcb54935325a/13a77/NotCachedResponse.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZC7OOA6i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://barranger.dev/static/d8ed9364d09b9cc036b1fcb54935325a/13a77/NotCachedResponse.png" alt="Not Cached Response"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This may not be the cleanest way of dealing with the issue, but when it comes to IE, when is it ever clean.  If you know of a better way, &lt;a href="https://twitter.com/barranger"&gt;let me know on twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>azurefunctions</category>
      <category>caching</category>
      <category>internetexplorer</category>
    </item>
    <item>
      <title>Using IoC in ASP.NET MVC</title>
      <dc:creator>Barranger Ridler</dc:creator>
      <pubDate>Mon, 22 Apr 2019 23:46:37 +0000</pubDate>
      <link>https://dev.to/barranger/using-ioc-in-asp-net-mvc-5995</link>
      <guid>https://dev.to/barranger/using-ioc-in-asp-net-mvc-5995</guid>
      <description>&lt;h2&gt;
  
  
  Why use IoC
&lt;/h2&gt;

&lt;p&gt;The reasons to use IoC are numerous, but specifically for ASP.NET it will allow you to keep code isolated into functional components, and allow you to migrate those functional components to newer/more appropriate technologies.&lt;/p&gt;

&lt;p&gt;Another major use for IoC is in testing. Where you will use full database repositories for production, using static data is often more than enough for unit tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which IoC Container
&lt;/h2&gt;

&lt;p&gt;Since you are currently using ASP.Net MVC , the best option currently is Unity (no not the game engine :) ). Not that .NET Core has it’s own IoC tooling, but most, if not all, of the options here will be easily migrated when the time comes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sample Project
&lt;/h2&gt;

&lt;p&gt;To illustrate the concepts in this doc, I’ve created the worlds simplest project to go through these examples, that project can be found &lt;a href="https://github.com/barranger/IoCTutorial"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The sample project will simply display a quote received form a quote service, that implements the &lt;code&gt;IQuoteService.cs&lt;/code&gt; Interface&lt;/p&gt;

&lt;h2&gt;
  
  
  Register Services
&lt;/h2&gt;

&lt;p&gt;Once adding the &lt;code&gt;Unity.MVC&lt;/code&gt; library via NuGet, you’ll find both &lt;code&gt;UnityConfig.cs&lt;/code&gt; and &lt;code&gt;UnityMvcActivator.cs&lt;/code&gt; in your &lt;code&gt;App_Start&lt;/code&gt; folder. The &lt;code&gt;UnityConfig.cs&lt;/code&gt; file is where you register the services, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void RegisterTypes(IUnityContainer container)
{
    // TODO: Register your type's mappings here.
    container.RegisterType&amp;lt;IQuoteService, StaticQuoteService&amp;gt;();
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;IQuoteService&lt;/code&gt; is the interface that we are registering, and &lt;code&gt;StaticQuoteService&lt;/code&gt; is the concrete implementation of the Interface that we will be exposing to the system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Services
&lt;/h2&gt;

&lt;p&gt;Once the services are setup, we’ll want to use them, in the case of Controllers, this is extremely easy as Unity will auto add them to our application if we declare the interfaces as parameter to our constructors like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private IQuoteService quoteService;

public HomeController(IQuoteService quoteService)
{
    this.quoteService = quoteService;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;we can then use the service anywhere in the controller, like the sample does for the &lt;code&gt;About&lt;/code&gt; route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public ActionResult About()
{
    ViewBag.Message = this.quoteService.GetRandomQuote();
    return View();
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Sometimes you will need to access the services outside of a controller, which we can also do by using &lt;code&gt;UnityConfig.Container&lt;/code&gt; like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static string GetRandomQuote()
 {
    var service = UnityConfig.Container.Resolve(typeof(IQuoteService), null) as IQuoteService;

    return $"From the RandomUtil: {service.GetRandomQuote()}";
 }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>ioc</category>
      <category>aspnet</category>
      <category>c</category>
      <category>azure</category>
    </item>
  </channel>
</rss>
