<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>try-catch-FAIL</title>
	<atom:link href="https://www.trycatchfail.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.trycatchfail.com</link>
	<description>Stories from the trenches of software development.</description>
	<lastBuildDate>Wed, 24 Oct 2018 02:29:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.3</generator>
	<item>
		<title>SpecsFor 7.0 Released!</title>
		<link>https://www.trycatchfail.com/2018/10/23/specsfor-7-0-released/</link>
					<comments>https://www.trycatchfail.com/2018/10/23/specsfor-7-0-released/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Matt Honeycutt]]></dc:creator>
		<pubDate>Tue, 23 Oct 2018 21:26:47 +0000</pubDate>
				<category><![CDATA[SpecsFor]]></category>
		<category><![CDATA[specsfor]]></category>
		<guid isPermaLink="false">https://www.trycatchfail.com/?p=1489</guid>

					<description><![CDATA[SpecsFor 7 final is here!]]></description>
										<content:encoded><![CDATA[<p>The final version of SpecsFor 7 is now available <a href="https://www.nuget.org/packages/SpecsFor/">via NuGet</a>!</p>
<p>This version includes some additional fixes via <a href="https://github.com/peitschie">Philip Peitsch</a> (thanks!!)</p>
<p>And of course, another &#8220;Thank You!&#8221; to <a href="https://catchco.com/">Catchco</a> and Robert &#8220;Stay Off My Lawn!&#8221; Simmons for their work on Autofac support.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.trycatchfail.com/2018/10/23/specsfor-7-0-released/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>SpecsFor 6 Released.  So is Version 7.</title>
		<link>https://www.trycatchfail.com/2018/09/11/specsfor-6-released-so-is-version-7/</link>
					<comments>https://www.trycatchfail.com/2018/09/11/specsfor-6-released-so-is-version-7/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Matt Honeycutt]]></dc:creator>
		<pubDate>Tue, 11 Sep 2018 18:03:44 +0000</pubDate>
				<category><![CDATA[SpecsFor]]></category>
		<category><![CDATA[specsfor]]></category>
		<guid isPermaLink="false">https://www.trycatchfail.com/?p=1485</guid>

					<description><![CDATA[Both SpecsFor 6 and 7 are now available.  SpecsFor 6 brings support for .NET Core, while SpecsFor 7 extends support to Autofac.]]></description>
										<content:encoded><![CDATA[<p>That&#8217;s right. Your eyes do not deceive you! There are <em>two</em> SpecsFor releases today! It&#8217;s BOGO Friday, read on to find out why!</p>
<p><span id="more-1485"></span></p>
<h2>SpecsFor 6 Final Released</h2>
<p>SpecsFor 6 has been hanging out in preview form for nearly <em>4 months!</em> I sort of lost track of the fact that I hadn&#8217;t published the final version.</p>
<p>Anyway, 6 Final is now out there, which includes .NET Core support. If you want to know more about this update, <a href="https://www.trycatchfail.com/2018/05/19/specsfor-mega-update/">check out this really old post</a>. For the most part, this version should be compatible with your existing SpecsFor projects, sans SpecsFor&lt;MVC&gt;, which is heading towards retirement.</p>
<h2>SpecsFor 7 Preview Released</h2>
<p>That brings us to SpecsFor 7. This version takes the first steps towards making SpecsFor more flexible. Thanks to the awesome contributions of <a href="https://catchco.com/">Catchco</a> developer Robert &#8220;I&#8217;m too good for social media!&#8221; Simmons, the core of SpecsFor is now IoC container agnostic! We&#8217;re shipping two official packages now, one for StructureMap, and one for Autofac. Creating your own adapter for other frameworks is actually fairly easy. Maybe Rob will write a guest post illustrating the process. Maybe showing integration with <a href="https://jasperfx.github.io/lamar/">Lamar</a>, perhaps?</p>
<p>If you&#8217;d like to see another container officially supported, feel free to submit a pull request!</p>
<p>We did remove several things from the v7 release. A lot of it was cruft that the project has picked up over the better part of a decade. Some features will probably be added back once I realize that I actually needed them&#8230;. ?</p>
<p>If you find something missing, drop an issue <a href="https://github.com/MattHoneycutt/SpecsFor/issues">here on Github</a>, and I&#8217;ll see about adding it back before v7 final is released.</p>
<h2>Installing SpecsFor 7</h2>
<p>There are now <em>4</em> SpecsFor packages you can choose from:</p>
<ul>
<li><a href="https://www.nuget.org/packages/SpecsFor.Core/">SpecsFor.Core</a> &#8211; This is the heart of SpecsFor. You shouldn&#8217;t install this directly <em>unless</em> you plan to write an adapter for a different IoC container.</li>
<li><a href="https://www.nuget.org/packages/SpecsFor.StructureMap/">SpecsFor.StructureMap</a> &#8211; If you want to use StructureMap&#8217;s automocking container, install this. If you&#8217;re using SpecsFor today, this package is what you want.</li>
<li><a href="https://www.nuget.org/packages/SpecsFor.Autofac/7.0.0-beta1">SpecsFor.Autofac</a> &#8211; This is the package you want if your main project uses Autofac.</li>
<li><a href="https://www.nuget.org/packages/SpecsFor/7.0.0-beta1">SpecsFor</a> &#8211; This is now just a meta package for <code>SpecsFor.StructureMap</code>. It exists just to make it easier to upgrade. At some point this will be the &#8220;kitchen sink&#8221; package that pulls in all the test helpers and conventions as the core of SpecsFor is refactored further..</li>
</ul>
<p>No matter which package you install, you will still derive from the base <code>SpecsFor&lt;T&gt;</code> class, just like you do today. The only thing that changes is which <code>using</code> statement you add:</p>
<pre><code>using Moq;
using NUnit.Framework;
using Should;
// Just "use" the namespace for whichever package you installed! 
using SpecsFor.StructureMap;

namespace SMTests
{
    public class WidgetSpecs
    {
        [TestFixture]
        public class when_starting_a_widget : SpecsFor&lt;Widget&gt;
        {
            protected override void When()
            {
                SUT.Start();
            }

            [Test]
            public void then_it_sets_the_status_to_running()
            {
                SUT.IsRunning.ShouldBeTrue();
            }

            [Test]
            public void then_it_raises_an_event()
            {
                GetMockFor&lt;IEvents&gt;()
                    .Verify(x =&gt; x.Publish(It.IsAny&lt;WidgetStarted&gt;()));
            }
        }
    }
}
</code></pre>
<blockquote><p>There is one issue with the current beta release: you must <strong>manually</strong> install both the <code>Microsoft.NET.Test.Sdk</code> and <code>NUnit3TestAdapter</code> packages. If you don&#8217;t, the test runner won&#8217;t see your specs. I&#8217;m trying to find a way to bake this in to SpecsFor, but I&#8217;m coming up empty. Help is appreciated!</p></blockquote>
<h2>What&#8217;s Next?</h2>
<p>I would like to get the whole <code>Microsoft.NET.Test.Sdk</code> dependency issue squared away, but I don&#8217;t know if that&#8217;s possible. .NET Core is still a mess in this area.</p>
<p>After that, the <a href="https://www.trycatchfail.com/2018/05/19/specsfor-mega-update">original roadmap for SpecsFor vNext</a> still applies. I would love to get things broken up where both xUnit and NUnit work.</p>
<p>If no major issues are reported, I plan to release v7 final early next week. Someone please remind me if I forget. ?</p>
<p>Thanks again to <a href="https://catchco.com/">Catchco</a> and Robert &#8220;what&#8217;s a twitter?&#8221; Simmons. This release wouldn&#8217;t have happened without your contributions!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.trycatchfail.com/2018/09/11/specsfor-6-released-so-is-version-7/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
		<item>
		<title>Link Roundup &#8211; Early-August 2018 Edition</title>
		<link>https://www.trycatchfail.com/2018/08/02/link-roundup-early-august-2018-edition/</link>
					<comments>https://www.trycatchfail.com/2018/08/02/link-roundup-early-august-2018-edition/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Matt Honeycutt]]></dc:creator>
		<pubDate>Thu, 02 Aug 2018 15:46:31 +0000</pubDate>
				<category><![CDATA[misc]]></category>
		<guid isPermaLink="false">https://www.trycatchfail.com/?p=1480</guid>

					<description><![CDATA[A collection of Angular, ASP.NET Core, Node, and general development links.]]></description>
										<content:encoded><![CDATA[<p>I spend a lot of time trying (and failing) to stay up to speed on the latest happenings in web development, Angular, .NET, Azure, and much more. These &#8220;roundup&#8221; posts contain all the interesting articles and tidbits I&#8217;ve come across. These links have helped me. I hope they can help you, too!</p>
<p><span id="more-1480"></span></p>
<p><strong><a href="https://github.com/sindresorhus/slugify">slugify</a></strong> is a handy npm package to convert a string to a &#8220;slug&#8221;. Think &#8220;Some Document Title&#8221; to &#8220;some-document-title&#8221;! I actually created a cmdlet using this for normalizing my blog post titles, but that&#8217;s a post for another day.</p>
<p>I spend about 75% of my day in Visual Studio Code, and I still didn&#8217;t know about many of the things <strong><a href="https://vscodecandothat.com/">in this list</a></strong>.</p>
<p>Are you remembering to unsubscribe your subscriptions in Angular? <strong><a href="https://netbasal.com/automagically-unsubscribe-in-angular-4487e9853a88">Netanel Basal took a stab at an automatic approach</a></strong>. Sadly it isn&#8217;t <em>completely</em> automatic, but it&#8217;s close!</p>
<p>I&#8217;m not usually a fan of abstraction for abstraction&#8217;s sake, but <strong><a href="https://blog.angular-university.io/how-to-build-angular2-apps-using-rxjs-observable-data-services-pitfalls-to-avoid/">observable services in Angular</a></strong> can be quite useful, and easy to build.</p>
<p>The Angular CDK is a great library. I plan to blog about some of the things I&#8217;m doing with it soon. In the meantime, check out <strong><a href="https://medium.com/@simonb90/hidden-features-of-angular-material-cdk-ee07066d73d1">how to build an expansion panel with it</a></strong>.</p>
<p>I&#8217;m still getting up to speed on Angular Animations. <strong><a href="https://alligator.io/angular/animation-angular/">This post at AlligatorIO</a></strong> is a bit dated, but it still helped me a lot.</p>
<p>Another good one from AlligatorIO: <strong><a href="https://alligator.io/angular/using-renderer2/">Angular has a built-in abstraction for DOM manipulation</a></strong>.</p>
<p>I&#8217;ve been using Moment.js for a <em>long</em> time, yet I didn&#8217;t realize how fully you could <strong><a href="https://momentjs.com/docs/#/customization/">customize it</a></strong>.</p>
<p>I love LINQ. It&#8217;s one of my favorite C# features. I spend quite a bit of time writing JavaScript though. Fortunately, many LINQ operations translate nicely to built-in JavaScript functions. <code>Array.some</code> can be used in JavaScript in much the same way you might use <code>Any</code> in C#. <strong><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some">Here&#8217;s more about that function</a></strong>.</p>
<p>&#8220;Scope&#8221; matters when dealing with variables in Angular templates. <strong><a href="http://weblogs.thinktecture.com/thomas/2017/05/use-angular-template-reference-variables-anywhere-in-the-template-not.html">I&#8217;ve been burned by this before</a></strong>.</p>
<p>Ever wanted to implement two-way bindings in Angular? <strong><a href="https://blog.angulartraining.com/tutorial-create-your-own-two-way-data-binding-in-angular-46487650ea82">Here&#8217;s how they actually work</a></strong>.</p>
<p>I&#8217;ve been working with various 3rd party systems and their webhooks. Both <strong><a href="https://ngrok.com">NGrok</a></strong> and <strong><a href="https://localtunnel.github.io/www/">localtunnel</a></strong> allow you to spin up your app locally, then get a public-facing URL that points to your app. This was invaluable, and works great with ASP.NET Core running locally.</p>
<p>NLog has been my go-to logging solution for years. Getting it up and running in ASP.NET Core 2 is actually <strong><a href="https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2">very easy</a></strong>.</p>
<p>Want to show an avatar for your users, but don&#8217;t want to manage the avatars yourself? Give an Email address to <strong><a href="https://unavatar.now.sh/">unavatar</a></strong>, and it will look across various social services to find a profile picture for you.</p>
<p><strong><a href="https://coursetro.com/posts/code/52/Trying-out-the-New-Angular-4-If-Else-Conditionals">if-else conditions</a></strong> are a new thing in Angular 4+. I somehow overlooked them until recently, but they do indeed help you write cleaner templates in some cases.</p>
<p><strong><a href="https://stackoverflow.com/a/49042444/32353">Lesson learned from Stack Overflow</a></strong>: if you want to accept form parameters in ASP.NET Core, use the <code>FromForm</code> attribute!</p>
<p>Need to parse a string containing a &#8220;full name&#8221; into first, middle, and last reliably? It isn&#8217;t as easy as just splitting on whitespace. Check out <strong><a href="https://github.com/aeshirey/NameParserSharp">NameParserSharp</a></strong> instead!</p>
<p>If you&#8217;re using just about <em>any</em> Angular libray, you&#8217;ve probably seen the <code>forRoot</code> pattern. <strong><a href="http://angularfirst.com/the-ngmodule-forroot-convention/">Here&#8217;s a good write-up</a></strong> if you&#8217;re curious what is actually going on, or if you want to know how you can use the pattern when building your own modules.</p>
<p>I like the idea of Parcel because it (mostly) Just Works, even with <strong><a href="https://javascripttuts.com/how-parcel-simplifies-modern-javascript-projects/">Vue SFC</a></strong>. Angular support doesn&#8217;t seem to be all the way there yet, but it&#8217;s still worth keeping an eye on.</p>
<p>There&#8217;s so much you can do with Microsoft Azure these days that it&#8217;s easy to miss out on cool features and capabilities. Michael Crump&#8217;s <strong><a href="https://www.michaelcrump.net/azure-tips-and-tricks-sorted-list/">Azure Tips and Tricks series</a></strong> is a great way to learn about all the awesome little things Azure can do!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.trycatchfail.com/2018/08/02/link-roundup-early-august-2018-edition/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>I Need Your Feedback &#8211; ASP.NET Core Application Framework Essentials</title>
		<link>https://www.trycatchfail.com/2018/07/19/i-need-your-feedback-asp-net-core-application-framework-essentials/</link>
					<comments>https://www.trycatchfail.com/2018/07/19/i-need-your-feedback-asp-net-core-application-framework-essentials/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Matt Honeycutt]]></dc:creator>
		<pubDate>Thu, 19 Jul 2018 16:55:36 +0000</pubDate>
				<category><![CDATA[asp.net core]]></category>
		<guid isPermaLink="false">https://www.trycatchfail.com/?p=1476</guid>

					<description><![CDATA[I'm finally creating a new "Build Your Own Application Framework" course.  Now is your chance to shape this course and make sure it covers the topics you care about!]]></description>
										<content:encoded><![CDATA[<p>I&#8217;m finally working on a new &#8220;application framework&#8221; course. I&#8217;d like <em>your</em> feedback on what content to include. Please read on to find out how to contribute!</p>
<p><span id="more-1476"></span></p>
<p>I released <a href="https://app.pluralsight.com/library/courses/build-application-framework-aspdotnet-mvc-5/table-of-contents">Build Your Own Application Framework with ASP.NET MVC 5</a> back in 2014. I never expected that course to take off the way it did, and it remains my most popular Pluralsight course to date.</p>
<p>Unfortunately, a lot has changed in four years, and a lot of the content in the course has not aged well. I&#8217;m constantly asked, &#8220;Are you going to make an updated application framework course??&#8221; After a couple of false-starts, I can finally answer that question with &#8220;Yes!&#8221;</p>
<p>But this course is going to be different.</p>
<p>First, I&#8217;m going to be self-publishing this course. That does <strong>not</strong> mean I&#8217;m finished making courses for Pluralsight! I just wanted to try an alternate publishing medium this time.</p>
<p>Second, my goal is to cover only what I consider absolutely <strong>essential</strong>, and only for ASP.NET Core. That means no Angular, no Aurelia, just server-side .NET code. Assuming there is sufficient interest, I&#8217;d like to do an app framework course that covers topics for Angular at a later date.</p>
<p>Third, I want to create this course out in the open. I want feedback from the community early and often.</p>
<p>To that end, here are the major topics I&#8217;m planning on covering in this course. Please drop me a note either in the comments below or <a href="https://twitter.com/matthoneycutt">via twitter (@matthoneycutt)</a> and let me know what you think. Are there things I&#8217;m not covering that you would like to see? Things I&#8217;m covering that you don&#8217;t care about? <strong>I want to hear from you!</strong></p>
<h2>Overview</h2>
<p>The course will cover several tools and techniques, including:</p>
<ul>
<li>Lamar</li>
<li>AutoMapper</li>
<li>MediatR</li>
<li>Entity Framework Core</li>
</ul>
<h3>Turbo-Charging ASP.NET Core IoC with Lamar</h3>
<p>Learn about the benefits of <a href="https://jasperfx.github.io/lamar/">Lamar</a> over the built-in Microsoft DI container. You&#8217;ll see how to add Lamar to an existing project, how to organize things into registries, and how to leverage type scanning and conventions to make your code easier to maintain while opening up new patterns that can help you solve problems more efficiently.</p>
<h3>Streamlining Your Controllers</h3>
<p>Out of the box, ASP.NET Core controllers can quickly become a mess of attributes, magic strings, validation, data access, and business logic. See how a few simple changes can help you organize your code better, eliminate attribute soup, tame magic strings, and eliminate tedious property assignments.</p>
<h3>Tame Your Data Access and Business Logic</h3>
<p>Continuing on, you&#8217;ll see how to reduce down the amount of code that lives in your controllers to something more manageable, how to eliminate architecture layers that aren&#8217;t providing value, and how to push cross-cutting concerns out of your controllers.</p>
<h2>Your Feedback Is Important!</h2>
<p>So what do you think? If this &#8220;Essentials&#8221; course is something you are interested in, please let me know what you think of the outline.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.trycatchfail.com/2018/07/19/i-need-your-feedback-asp-net-core-application-framework-essentials/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Passing Data from ASP.NET Core to Angular</title>
		<link>https://www.trycatchfail.com/2018/07/16/passing-data-from-asp-net-core-to-angular/</link>
					<comments>https://www.trycatchfail.com/2018/07/16/passing-data-from-asp-net-core-to-angular/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Matt Honeycutt]]></dc:creator>
		<pubDate>Mon, 16 Jul 2018 15:18:27 +0000</pubDate>
				<category><![CDATA[asp.net core]]></category>
		<category><![CDATA[angular]]></category>
		<guid isPermaLink="false">https://www.trycatchfail.com/?p=1472</guid>

					<description><![CDATA[Every application needs some configuration data. For ASP.NET Core applications, we can pull configuration data from JSON files, environment variables, or anywhere else we want. For Angular applications, we can define environment-specific configuration files that are automatically wired up for us based on our build configuration. But what do we do when we need to...]]></description>
										<content:encoded><![CDATA[<p>Every application needs some configuration data. For ASP.NET Core applications, we can pull configuration data from JSON files, environment variables, or anywhere else we want. For Angular applications, we can define environment-specific configuration files that are automatically wired up for us based on our build configuration.</p>
<p>But what do we do when we need to share configuration data between Angular and ASP.NET Core? Here is one option for you.</p>
<p><span id="more-1472"></span></p>
<h2>Credit Where Credit is Due</h2>
<p>I actually started writing this post back at the beginning of May, but I never finished it. In the time since I started working on this, I noticed that <a href="https://elanderson.net/2018/05/pass-asp-net-core-appsettings-values-to-angular-via-an-api-call/">Eric Anderson tackled the very same problem on his blog</a>. His solution is similar to mine, especially on the client-side of things (nice job, Eric!). But I tackled things a bit differently on the server-side, and I decided to finish out my post just to elaborate on a few of the concepts a bit further.</p>
<h2>The Challenge</h2>
<p>This post is partially in response to a question from Nigel over at my <a href="https://app.pluralsight.com/library/courses/build-application-framework-aspdotnet-mvc-5/table-of-contents">&#8220;Build Your Own App Framework&#8221; Pluralsight Course</a>. One of the techniques I show in that course is how to pass data from ASP.NET MVC to Angular. I also show <a href="https://www.trycatchfail.com/2015/01/30/passing-data-to-angular-from-asp-net-mvc-views/">that same technique here on my blog</a>, so feel free to check it out if you&#8217;re curious.</p>
<p>The pattern was more applicable in the AngularJS/ASP.NET MVC (non-Core) days, because AngularJS could be used to create &#8220;Silo SPAs&#8221; quite easily, and it had no built-in configuration system to speak of.</p>
<p>Neither of those things are true with ASP.NET Core and Angular 2+. Angular no longer lends itself to the &#8220;Silo SPA&#8221; approach, and it <em>does</em> have a configuration system built in.</p>
<p>But that doesn&#8217;t mean the idea of passing configuration between the two systems is irrelevant.</p>
<p>There&#8217;s still some configuration data that might make sense to have shared between both Angular and your ASP.NET Core application. Examples of things that might make sense to share both server and client-side are things like <strong>public</strong> keys, or non-sensitive tokens, or, in a multi-tenant application, information about the current tenant.</p>
<p>So how can we share config? How can we specify config settings exactly once, and leverage them in both places?</p>
<h2>The Solution</h2>
<p>The simplest solution I&#8217;ve come up with is this: expose configuration data from ASP.NET Core via an API endpoint, and have Angular make a request to this endpoint during application startup.</p>
<p>The endpoint could return whatever makes sense. A simple JSON object will probably suffice in many cases:</p>
<pre><code class="language-json">{
    "setting1": "value1",
    "setting2": "value2",
    //And so on...
}
</code></pre>
<p>That <em>sounds</em> trivial, but there are a couple of gotchas, as we&#8217;ll soon see!</p>
<h2>Defining the API Endpoint</h2>
<p>Let&#8217;s go ahead and start by making an API endpoint to return config data:</p>
<pre><code class="language-csharp">    [ApiController, Route("api/config")]
    public class ConfigController : Controller
    {
        [HttpGet("")]
        public IActionResult Get()
        {
            
        }
    }
</code></pre>
<p>Easy enough so far. Now we want to grab <em>specific</em> config settings from our applications configuration data, and pass those down. I emphasize <strong>specific</strong>, because your configuration probably has lots of things you <strong>don&#8217;t</strong> want to expose like this. <strong>This is doubly true in ASP.NET Core</strong>, because by default, your config data will also contain all of your environment variables!</p>
<blockquote><p><strong>Remember that anything you return from your API is visible to the end user</strong>. It&#8217;s effectively in the hands of the enemy! If you return everything, you are more than likely passing sensitive information, including connection strings, and that would be a Bad Thing<sup>TM</sup>. Be selective, and only return the minimum!</p></blockquote>
<p>We could manually extract and pass config data, which would look like this:</p>
<pre><code class="language-csharp">public class ConfigController : Controller
{
    private readonly IConfiguration _config;

    public ConfigController(IConfiguration config)
    {
        _config = config;
    }

    [HttpGet("")]
    public IActionResult Get()
    {
        return Ok(new
        {
           //Grab whatever settings your client app needs, and pass them back!
           clientName = _config.GetSection("CustomerSettings:ClientName").Value,
           defaultPage = _config.GetSection("CustomerSettings:DefaultPage").Value
        });
    }
}
</code></pre>
<p>Or, if we choose to keep all of our shared config in a single section, and just pass the entire section:</p>
<pre><code class="language-csharp">public class ConfigController : Controller
{
    private readonly IConfiguration _config;

    public ConfigController(IConfiguration config)
    {
        _config = config;
    }

    [HttpGet("")]
    public IActionResult Get()
    {
        var targetSection = "customerSettings";
        //The magic happens here! 
        return Ok(_config.GetSection(targetSection)
            .AsEnumerable()
            .Where(x =&gt; x.Key != targetSection)
            // Since we are enumerating the root, 
            // each key will be prefixed with our 
            // target section, so we need to strip
            // that prefix off.
            .ToDictionary(x =&gt; x.Key.RemoveStart($"{targetSection}:"), x =&gt; x.Value));
    }
}
</code></pre>
<p>This approach has one nice benefit: if you add a new config setting, it will automatically be passed down. Of course, it&#8217;s also a bit dangerous, since if you accidentally add a sensitive setting in there, you might not realize it is being exposed to clients via the API.</p>
<p>There&#8217;s a bit more we could do here if we wanted. We could grab information about the current user, or in a multi-tenant application we could grab information about the current tenant. We could add caching, too, if we wanted.</p>
<p>Also note that while I&#8217;m using .NET Core&#8217;s <code>IConfiguration</code> provider, you could actually pull &#8220;config&#8221; settings from another source, too. If you store some config data in a database, you could retrieve that here, and pass it back as well.</p>
<p>That takes care of the ASP.NET Core side of things, so let&#8217;s take a look at the Angular-side.</p>
<h2>Loading Configuration</h2>
<p>So we have our config endpoint, we have our client app, it should be trivial to pull that data in&#8230; right??</p>
<p>Not so fast.</p>
<p>This is where things get a <em>tad</em> tricky.</p>
<p>Calling the endpoint <em>is</em> easy, but that&#8217;s an <em>asynchronous</em> call! Our app probably needs this data before it does anything else!</p>
<p>It turns out that Angular actually supports <strong>application initializers</strong> that are a perfect fit for what we&#8217;re doing here.</p>
<p>Let&#8217;s start by building a service that will allow us to retrieve configuration data from our API.</p>
<h2>Creating the Configuration Provider</h2>
<p>Let&#8217;s define a service to wrap our config data. I&#8217;m going to keep things loosely-typed, but you could define strongly-typed wrappers instead of exposing the configuration data directly:</p>
<pre><code class="language-ts">import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'

// This represents our raw config from the server.
// We could define a strongly-typed config class
// that wraps the values from the server, but for
// this simple demo, we won't bother with that.
export declare type AppConfig = { [key: string]: string };

@Injectable()
export class AppConfigProvider {

  private config: AppConfig;

  constructor(
    private httpClient: HttpClient
    ) { }

  loadConfig() {
    return this.httpClient.get&lt;AppConfig&gt;('api/config').toPromise().then(x =&gt; {
      this.config = x;
    });
  }

  getConfig() {
    return this.config;
  }
}
</code></pre>
<p>We also need to add our config provider to our application module&#8217;s providers:</p>
<pre><code class="language-ts">// SNIP
import { AppConfigProvider } from './config/app-config-provider.service';

@NgModule({  
  // SNIP
  providers: [
    AppConfigProvider
    ],
  // SNIP
})
export class AppModule { }

</code></pre>
<p>Now our components (and other services!) can inject <code>AppConfigProvider</code> in order to have access to our <code>AppConfig</code> data.</p>
<p>Or they <em>would</em> be able to do that, if only someone was actually calling <code>loadConfig</code> first!</p>
<h2>Hooking in to Angular&#8217;s Application Initialization</h2>
<p>The challenge now is to make sure our <code>loadConfig</code> function is called <strong>before</strong> anything else happens in our app. It turns out that Angular has built-in support for scenarios just like this in the form of <a href="https://hackernoon.com/hook-into-angular-initialization-process-add41a6b7e">application initializers</a>.</p>
<blockquote><p>Note that app initializers are considered experimental still, so their exact implementation and behavior may change in future releases.</p></blockquote>
<p>Over in our <code>app.module</code>, we can register a new app initializer like so:</p>
<pre><code class="language-ts">// SNIP
import { NgModule, APP_INITIALIZER } from '@angular/core';
// SNIP

@NgModule({
  // SNIP
  providers: [
    AppConfigProvider,
    {
      provide: APP_INITIALIZER,
      useFactory: (appConfigProvider: AppConfigProvider) =&gt; {
         return () =&gt; appConfigProvider.loadConfig();
      },
      multi: true,
      deps: [AppConfigProvider]
    }
    ],
  // SNIP
})
export class AppModule { }

</code></pre>
<p>There&#8217;s actually a lot going on here, so let&#8217;s focus in a bit:</p>
<pre><code class="language-ts">{
  provide: APP_INITIALIZER,
  useFactory: (appConfigProvider: AppConfigProvider) =&gt; {
     return () =&gt; appConfigProvider.loadConfig();
  },
  multi: true,
  deps: [AppConfigProvider]
}
</code></pre>
<p>See that <code>provide</code>? Statement? That tells Angular that we&#8217;re providing a service with <code>APP_INITIALIZER</code> as its injection token. This particular token is used by Angular during application initialization (surprising, I know!) Angular will take care of instantiating our service and executing it automatically.</p>
<p>And that <code>useFactory</code> part? That registers the factory that Angular will grab during app initialization. It&#8217;s a bit meta, but Angular expects our factory to be a function that returns a function. And that function we return is calling our <code>loadConfig</code> function.</p>
<p>Since <em>that</em> function returns a promise, Angular will pause app initialization until the promise is resolved. And that&#8217;s exactly what we want: Angular won&#8217;t finish initializing until our <code>AppConfigProvider</code> has loaded its configuration data.</p>
<p>The final two parts of our provider definition are fairly simple: <code>multi</code> tells Angular that it&#8217;s perfectly fine if there are multiple app initializer providers registered. The <code>deps</code> part tells Angular that our factory has a single dependency, <code>AppConfigProvider</code>, which will be passed to our factory function.</p>
<h2>Putting It All Together&#8230;</h2>
<p>Now that we have all the pieces in place, we should be able to inject our <code>AppConfigProvider</code> anywhere we need it, like in our <code>home</code> component:</p>
<pre><code class="language-ts">import { Component } from '@angular/core';
import { AppConfigProvider, AppConfig } from '../config/app-config-provider.service';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
})
export class HomeComponent {
  appConfig: AppConfig;

  constructor(
    private appConfigProvider: AppConfigProvider
  ) {
    this.appConfig = appConfigProvider.getConfig();
  }
}
</code></pre>
<p>And at runtime, our component will receive the provider <em>after</em> it has already loaded the configuration data:</p>
<p><img decoding="async" src="https://www.trycatchfail.com/wp-content/uploads/2018/07/BlogPostspassing-data-from-asp-net-mvc-core-to-angular-01.png" alt="" /></p>
<h2>Wrapping Up</h2>
<p>So that&#8217;s one approach to sharing data between ASP.NET Core and Angular. If you know of others, please feel free to share them in the comments!</p>
<p>Oh, and if you want the code, <a href="https://github.com/MattHoneycutt/HeroicSamples.PassingDataFromAspNetCoreToAngular">it is available on GitHub</a>.</p>
<p>Enjoy!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.trycatchfail.com/2018/07/16/passing-data-from-asp-net-core-to-angular/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>New Course: Getting Started with Azure IoT Hub</title>
		<link>https://www.trycatchfail.com/2018/05/30/new-course-getting-started-with-azure-iot-hub/</link>
					<comments>https://www.trycatchfail.com/2018/05/30/new-course-getting-started-with-azure-iot-hub/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Matt Honeycutt]]></dc:creator>
		<pubDate>Wed, 30 May 2018 10:38:30 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iot hub]]></category>
		<guid isPermaLink="false">https://www.trycatchfail.com/?p=1467</guid>

					<description><![CDATA[This post may seem a bit off-topic, but for the past several years, when I&#8217;m not building Angular and ASP.NET applications, I&#8217;ve been working in the Internet of Things. Microsoft Azure IoT Hub has been a game-changer in this space, and my latest Pluralsight course, Azure IoT Hub for Developers: Getting Started, was crafted to...]]></description>
										<content:encoded><![CDATA[<p>This post may seem a bit off-topic, but for the past several years, when I&#8217;m not building Angular and ASP.NET applications, I&#8217;ve been working in the Internet of Things. Microsoft Azure IoT Hub has been a game-changer in this space, and <a href="https://app.pluralsight.com/library/courses/azure-iot-hub-developers-getting-started">my latest Pluralsight course</a>, <a href="https://app.pluralsight.com/library/courses/azure-iot-hub-developers-getting-started">Azure IoT Hub for Developers: Getting Started</a>, was crafted to help you get up to speed with it quickly.</p>
<p><span id="more-1467"></span></p>
<h1>Why IoT?</h1>
<p>So if you&#8217;re a web developer, why should you care about IoT? It&#8217;s just one more thing to try and learn, right?</p>
<p>Well, there are actually about 2 <strong>trillion</strong> reasons: IoT, as the Internet of Things is commonly know, is predicted to enable roughly 2 <strong>TRILLION</strong> (with a <em>T</em>) dollars in productivity improvements by 2022. <a href="https://www.atkearney.com/web/atkearney-silicon-valley/future-of-the-internet-of-things">source</a></p>
<p>Security spending related to IoT <em>alone</em> will surpass 3 billion by 2021. <a href="https://www.gartner.com/newsroom/id/3869181">source</a></p>
<p>And Microsoft is throwing money at IoT, too, to the tune of 5 <strong>billion</strong> by 2022. <a href="https://blogs.microsoft.com/iot/2018/04/04/microsoft-will-invest-5-billion-in-iot-heres-why/">source</a></p>
<p>That&#8217;s why you should care about IoT: there&#8217;s going to be a tremendous amount of money spent in this area, which means new opportunities for you as a developer!</p>
<p>Besides the money and new opportunities, building IoT solutions is just a ton of fun. There&#8217;s something incredibly satisfying about wiring a device together, then communicating with it remotely via IoT Hub.</p>
<h1>What You&#8217;ll Learn</h1>
<p>My course is meant to give you a solid foundation on both the device-side and cloud-side of things. Topics you&#8217;ll learn about include:</p>
<ul>
<li>Azure IoT Hub itself</li>
<li>Creating a (virtual) device application with .NET Core</li>
<li>Sending commands and messages</li>
<li>Processing messages using IoT Hub</li>
</ul>
<p>By the end of the course, you&#8217;ll have a solid foundation for building a solution on Microsoft Azure IoT Hub.</p>
<p>So give it a try, and let me know what you think of this course!</p>
<p><a href="https://app.pluralsight.com/library/courses/azure-iot-hub-developers-getting-started">Azure IoT Hub for Developers: Getting Started</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.trycatchfail.com/2018/05/30/new-course-getting-started-with-azure-iot-hub/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>SpecsFor Mega Update</title>
		<link>https://www.trycatchfail.com/2018/05/19/specsfor-mega-update/</link>
					<comments>https://www.trycatchfail.com/2018/05/19/specsfor-mega-update/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Matt Honeycutt]]></dc:creator>
		<pubDate>Sat, 19 May 2018 15:26:58 +0000</pubDate>
				<category><![CDATA[SpecsFor]]></category>
		<category><![CDATA[.net core]]></category>
		<category><![CDATA[specsfor]]></category>
		<guid isPermaLink="false">https://www.trycatchfail.com/?p=1461</guid>

					<description><![CDATA[There&#8217;s actually news in the world of SpecsFor! .NET Standard support has arrived, plans for the next version are becoming a little more concrete&#8230; read on if you want to catch up! The Journey to .NET Standard &#8220;One can only slack for so long&#8230;&#8221; &#8211; Me, when I finally started work on .NET Standard support...]]></description>
										<content:encoded><![CDATA[<p>There&#8217;s actually news in the world of SpecsFor! .NET Standard support has arrived, plans for the next version are becoming a <em>little</em> more concrete&#8230; read on if you want to catch up!</p>
<p><span id="more-1461"></span></p>
<h2>The Journey to .NET Standard</h2>
<blockquote><p>&#8220;One can only slack for so long&#8230;&#8221; &#8211; Me, when I finally started work on .NET Standard support for SpecsFor</p></blockquote>
<p>I am probably one of the worst open-source project maintainers, ever. I&#8217;ve let SpecsFor languish without .NET Standard support for far too long.</p>
<p>I had my reasons though. Prior to 2018, most of my production work still targeted .NET 4.7. To be perfectly honest, I didn&#8217;t even <em>like</em> .NET Core until 2.1. I feel like we&#8217;re just now hitting the point where it&#8217;s an actual, viable, stable solution. I&#8217;m only just now diving in to the pool all the way.</p>
<p>So there was that lack of motivation, but then there were also the dependencies!</p>
<p>SpecsFor is actually built on top of several different libraries: <a href="http://nunit.org/"><code>NUnit</code></a>, Jeremy Miller&#8217;s <a href="http://structuremap.github.io/"><code>StructureMap</code></a>, kzu&#8217;s <a href="https://github.com/moq/moq4"><code>Moq</code></a>, Derek Greer&#8217;s <a href="https://github.com/derekgreer/expectedObjects"><code>ExpectedObjects</code></a>, and Eric Hexter&#8217;s <a href="https://github.com/erichexter/Should"><code>Should</code></a>. SpecsFor has varying degrees of dependencies on each of these libraries. You might (correctly) say it is tightly coupled to each of these projects.</p>
<p>This made perfect sense to me at the time. SpecsFor was originally meant to be a <em>highly</em> opinionated framework: you wrote specs using a specific combination of tools, in a specific way, with some glue in the middle to help make things work together nicely.</p>
<p>That&#8217;s an awesome idea, and it works fine&#8230; until one of those dependencies stops being maintained. That is exactly what happened to <code>Should</code>. In order for SpecsFor to target .NET Standard, I would have to break that dependency on <code>Should</code>.</p>
<p>That turned out to be more difficult than you might think, and in the end, I actually ended up <strong>forking</strong> <code>Should</code>, reworking that for .NET Standard, and shipping that as its own NuGet package, <a href="E:%5CProjects%5Cspecsfor%5CSpecsFor.Mvc%5CSpecsFor.Mvc.5.1.0.nupkg"><code>Should-DotNetStandard</code></a>.</p>
<p>This is a temporary solution for the 6.0 release. I don&#8217;t plan to support <code>Should-DotNetStandard</code> for long. In fact, I don&#8217;t plan for SpecsFor to remain coupled to much of anything in the future. But we&#8217;ll get to that in a second! Let&#8217;s talk about ASP.NET MVC.</p>
<h2>Saying Goodbye to SpecsFor.Mvc</h2>
<p>As much as it pains me, I&#8217;m planning to retire SpecsFor.Mvc. I&#8217;ll continue to fix bugs and accept pull requests for the foreseeable future, but it will not be getting ASP.NET Core support. If you want to use it for ASP.NET MVC 5, feel free to do so! But don&#8217;t expect to see it working with ASP.NET Core.</p>
<p>I have my reasons for retiring this project. It was <em>always</em> difficult to maintain and support, but more than that, I just don&#8217;t feel that there&#8217;s much of a fit for it in ASP.NET Core. Microsoft decided to basically abandon the whole strongly-typed approach to things when they deprecated <code>HtmlHelpers</code> and went with <code>TagHelpers</code> in ASP.NET Core. Beyond even <em>that</em>, there&#8217;s the fact that most apps, at least the ones I work with, are built on front-end frameworks like Angular, and those frameworks have their own tools for UI testing.</p>
<p>So that&#8217;s that: SpecsFor.Mvc is still out there and will still work for ASP.NET MVC 5 apps. I&#8217;ll still try to fix bugs as they are found, and I&#8217;m still accepting pull requests. In fact, I&#8217;m shipping a small update today thanks to a pull request from <a href="https://twitter.com/divinci">Nick Divinci</a>, plus a few minor improvements to the code itself.</p>
<p><strong>But</strong>, unless someone wants to step in and champion the work (or pay me to champion it?), it won&#8217;t be following its sibling into the land of .NET Standard.</p>
<p>With that depressing bit out of the way, let&#8217;s talk about what&#8217;s next for SpecsFor!</p>
<h2>SpecsFor vNext</h2>
<p>My focus with the SpecsFor 6.0 release is to get things working stably as a .NET Standard package. I don&#8217;t plan to add new features to this version. I just want to get it all working, and working well, on .NET Core, .NET Full, etc.</p>
<p>I have very different, probably overly-ambitious, goals for SpecsFor 7.0.</p>
<p>For SpecsFor 7.0, I want to accomplish two contradictory goals at once: provide a solution that is flexible and can be used with the tools of your choice, and provide a highly-opinionated solution with the latest-and-greatest tooling. How can I do both of these things at once? Here&#8217;s what I&#8217;m thinking:</p>
<ul>
<li>SpecsFor.Core &#8211; The core &#8220;engine&#8221; of SpecsFor. No dependency on anything else, just some abstractions.</li>
<li>SpecsFor.Assertions &#8211; Framework-agnostic test helpers. Things like <code>ShouldLookLike</code> and other common helpers would live in this package.</li>
<li>SpecsFor.Web &#8211; Framework-agnostic helpers to simplify common ASP.NET Core testing scenarios.</li>
<li>SpecsFor.EF &#8211; Framework-agnostic helpers to simplify common Entity Framework testing scenarios, enabling simple, easy integration testing.</li>
</ul>
<p>Those will be the &#8220;core&#8221; packages, with as few dependencies as I can get away with in each. The idea is that you can pick and choose what you need, configure it to use whatever testing framework, mocking framework, and assertion library that you want. I hope to have packages available for common configurations, probably something like:</p>
<ul>
<li>SpecsFor.NUnit &#8211; Wiring to enable SpecsFor to work on top of NUnit.</li>
<li>SpecsFor.XUnit &#8211; Wiring to enable SpecsFor to work on top of XUnit.</li>
<li>SpecsFor.StructureMap &#8211; Configures SpecsFor to use an auto-mocking StructureMap container for creating everything (just like it does today).</li>
<li>SpecsFor.SimpleInjector &#8211; Configures SpecsFor to use an auto-mocking SimpleInjector container.</li>
<li>SpecsFor.Moq &#8211; Configures SpecsFor to use Moq for creating mocks.</li>
<li>SpecsFor.FakeItEasy &#8211; Configures SpecsFor to use FakeItEasy for creating mocks.</li>
</ul>
<p>You get the idea: small, modular packages, that you can mix and match to fit however you want to write your specs.</p>
<p>But I still plan to have a &#8220;mega&#8221; package:</p>
<ul>
<li>SpecsFor &#8211; The highly-opinionated kitchen sink. Built on SpecsFor.Core, wired up to use a specific testing framework, a specific set of assertions, a specific mocking library, etc.</li>
</ul>
<p>I&#8217;m not sure exactly which tools I&#8217;ll choose for this mega package yet. I know I want to use <a href="https://github.com/shouldly/shouldly"><code>Shouldly</code></a> for its awesome exception messages. Other than that, I may end up keeping the current set of tooling. I&#8217;m also tempted by XUnit, but its approach to testing is not really compatible with SpecsFor, and I&#8217;m still not sure how I&#8217;m going to make SpecsFor work on top of it. If you think I should ditch one tool for another, let me now.</p>
<p>It&#8217;s going to be a lot of work, but I think that will greatly open up the places that SpecsFor can be applied. Plus it&#8217;ll be fun (I think)!</p>
<h2>Interested in Helping?</h2>
<p>All of that said, 7.0 is going to be a lot of work. I&#8217;d love to get some help on this. If you&#8217;re interested in championing any one of these packages, or helping with the core redesign, please contact me! And if you work for a company that is using (or interested in using) SpecsFor, and you&#8217;d like to sponsor some of the new work, let me know! ?</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.trycatchfail.com/2018/05/19/specsfor-mega-update/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>Using Angular 6 with Visual Studio 2017</title>
		<link>https://www.trycatchfail.com/2018/05/18/using-angular-6-with-visual-studio-2017/</link>
					<comments>https://www.trycatchfail.com/2018/05/18/using-angular-6-with-visual-studio-2017/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Matt Honeycutt]]></dc:creator>
		<pubDate>Fri, 18 May 2018 15:25:56 +0000</pubDate>
				<category><![CDATA[asp.net core]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[visual studio 2017]]></category>
		<guid isPermaLink="false">https://www.trycatchfail.com/?p=1457</guid>

					<description><![CDATA[Angular 6 is out! That&#8217;s great, except that the Visual Studio 2017 Angular templates haven&#8217;t been updated yet. BUT, all is not lost, because it&#8217;s actually (relatively) easy to upgrade. Let&#8217;s take a look! Getting Started Angular 6 includes a lot of tooling improvements, so it&#8217;s worth the upgrade. And thanks to the new ng...]]></description>
										<content:encoded><![CDATA[<p>Angular 6 is out! That&#8217;s great, except that the Visual Studio 2017 Angular templates haven&#8217;t been updated yet. BUT, all is not lost, because it&#8217;s actually (relatively) easy to upgrade. Let&#8217;s take a look!</p>
<p><span id="more-1457"></span></p>
<h2>Getting Started</h2>
<p>Angular 6 includes a <a href="https://github.com/angular/angular/blob/master/CHANGELOG.md#600-2018-05-03">lot of tooling improvements</a>, so it&#8217;s worth the upgrade. And thanks to the new <code>ng upgrade</code> command, upgrading your Angular projects has never been easier!</p>
<p>We&#8217;re going to start with the &#8220;enhanced&#8221; project we made in a previous post. You can check that project out <a href="https://www.trycatchfail.com/2018/03/22/creating-a-new-asp-net-core-2-1-preview-project-with-angular/">here</a>. The steps would be <em>mostly</em> the same if you were to take a stock Visual Studio Angular project.</p>
<p>If you have a more complex Angular project and want to see how difficult it will be to upgrade, you can use the new <a href="https://update.angular.io/">Angular Update Guide</a>. But be warned! There are still <a href="https://github.com/angular/angular-cli/issues/10621">issues</a> with <code>ng update</code>, so the update guide might not work for you.</p>
<h2>Installing Angular 6</h2>
<p>The first thing we need to do is install the Angular 6 CLI. You can do this globally from the command prompt of your choice:</p>
<pre><code>npm i -g @angular/cli
</code></pre>
<p>This gives us the latest-and-greatest Angular CLI. You can verify that you have it installed by running <code>ng -v</code>. You should see something like this:</p>
<p><img decoding="async" src="https://www.trycatchfail.com/wp-content/uploads/2018/05/BlogPostsusing-angular-6-with-visual-studio-2017-01.png" alt="" /></p>
<h2>Upgrading Your Project&#8217;s Tooling</h2>
<p>We have Angular 6 installed globally, but our project has its own, local copy of the CLI, and that&#8217;s still the old version! We need to upgrade that, too! There&#8217;s a bit more work we have to do first though&#8230;</p>
<blockquote><p>I&#8217;m actually not going to do things the official way. The docs will tell you to upgrade the CLI first. I tried that, but ran into issues. I followed the workaround from <a href="https://github.com/angular/angular-cli/issues/10621">this issue</a> instead.</p></blockquote>
<p><strong>Before you open your Visual Studio solution</strong>, navigate to the ClientApp directory of your project using your favorite command prompt.</p>
<p>First, use <code>ng update</code> to update all of your Angular references:</p>
<pre><code>ng update
</code></pre>
<p>Next, update <code>rxjs</code> to take care of a dependency issue:</p>
<pre><code>ng update rxjs
</code></pre>
<p><strong>Now</strong> you can use <code>ng update</code> to update your project&#8217;s CLI:</p>
<pre><code>ng update @angular/cli
</code></pre>
<p>This will remove your existing <code>.angular-cli.json</code> file, and add a new <code>angular.json</code> file. It will also update a handful of other files, too.</p>
<p>If you have other dependencies, such as Angular Material, you will need to perform some additional steps. The <a href="https://update.angular.io/">Angular Update Guide</a> should get you pointed in the right direction.</p>
<p>We&#8217;re getting there! Now we&#8217;re ready to turn our attention to fixing up our project&#8217;s integration with Visual Studio 2017.</p>
<h2>Fixing the Tasks</h2>
<p>The old Angular project template called <code>ng serve</code> and <code>ng build</code> with the <code>extract-css</code> option. That option is no longer valid, so we need to remove it from our npm tasks.</p>
<p>Open your <code>package.json</code> file, and change the entries in the <code>scripts</code> section to remove the obsolete option from both the <code>start</code> and <code>build</code> tasks. You should have something like this after the change:</p>
<pre><code class="language-json">{
  //snip
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build:ssr": "npm run build -- --app=ssr --output-hashing=media",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  //snip
}
</code></pre>
<p>Now the <code>start</code> and <code>build</code> tasks should work again.</p>
<h2>Putting it All Together</h2>
<p>It <em>should</em> be safe to open everything in Visual Studio now. Task Runner Explorer <em>should</em> be able to run the npm <code>start</code> task without error, and we <em>should</em> be able to go ahead and run our app&#8230; You can go ahead and try it, if you want.</p>
<p>But me, I&#8217;m a bit skeptical&#8230; how will I know <em>for sure</em> that my app is actually using Angular 6?</p>
<p>There are a couple of ways, but here&#8217;s an easy one: I can make a small adjustment to the home view so that it displays the current Angular version.</p>
<p>In <code>home.component.ts</code>, I can import <code>VERSION</code> and make its <code>full</code> property available off of the component:</p>
<pre><code class="language-ts">import { Component, VERSION } from '@angular/core';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
})
export class HomeComponent {

  version: string;

  constructor() {
    this.version = VERSION.full;
  }
}
</code></pre>
<p>Then I can display it in the view:</p>
<pre><code class="language-html">&lt;h1&gt;Hello, world!&lt;/h1&gt;
&lt;p&gt;You are running Angular {{version}}!&lt;/p&gt;
&lt;!-- snip --&gt;
</code></pre>
<p>Looks like it worked!</p>
<p><img decoding="async" src="https://www.trycatchfail.com/wp-content/uploads/2018/05/BlogPostsusing-angular-6-with-visual-studio-2017-03.png" alt="" /></p>
<h1>Get the Code</h1>
<p>So there you have it: upgrading to Angular 6 is easy, though not quite as easy as it should be yet due to issues with <code>ng upgrade</code>. I&#8217;m sure those kinks will be worked out, and once they are, it will be easier than ever to stay up to date with the latest and greatest of Angular.</p>
<p>The code for this demo is checked in to the same <a href="https://github.com/MattHoneycutt/HeroicSamples.AspNetCore21PreviewWithAngular">Github repository</a> that I used before. Feel free to check it out.</p>
<p>Did you find this post useful? Are there other topics you&#8217;d like to see me cover on this blog? Please drop me a comment below!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.trycatchfail.com/2018/05/18/using-angular-6-with-visual-studio-2017/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Heroic.AutoMapper for .NET Core Released!</title>
		<link>https://www.trycatchfail.com/2018/05/09/heroic-automapper-for-net-core-released/</link>
					<comments>https://www.trycatchfail.com/2018/05/09/heroic-automapper-for-net-core-released/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Matt Honeycutt]]></dc:creator>
		<pubDate>Wed, 09 May 2018 19:13:15 +0000</pubDate>
				<category><![CDATA[automapper]]></category>
		<category><![CDATA[heroic-framework]]></category>
		<category><![CDATA[.net core]]></category>
		<guid isPermaLink="false">https://www.trycatchfail.com/?p=1451</guid>

					<description><![CDATA[It&#8217;s been a long time coming, but Heroic.AutoMapper 5.0 is now live on NuGet, and with it, support for .NET Standard (and therefore .NET Core)! Breaking Change This is a breaking change from previous versions. If you are upgrading from 4.0.0, you will need to make a small change. Previous versions used WebActivatorEx to automatically...]]></description>
										<content:encoded><![CDATA[<p>It&#8217;s been a long time coming, but Heroic.AutoMapper 5.0 is now live on NuGet, and with it, support for .NET Standard (and therefore .NET Core)!</p>
<p><span id="more-1451"></span></p>
<h2>Breaking Change</h2>
<p>This is a breaking change from previous versions. If you are upgrading from <code>4.0.0</code>, you will need to make a small change.</p>
<p>Previous versions used <code>WebActivatorEx</code> to automatically wire things up for you, usually with no code changes on your part. That&#8217;s no longer the case with <code>5.0.0</code>.</p>
<p>Instead, you will need to <strong>explicitly</strong> call one of <code>HeroicAutoMapperConfigurator</code>&#8216;s configuration methods, like so:</p>
<pre><code class="language-csharp">    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            HeroicAutoMapperConfigurator.LoadMapsFromAssemblyContainingTypeAndReferencedAssemblies&lt;HomeController&gt;();
        }
    }
</code></pre>
<p>But there&#8217;s a reason for that change&#8230;</p>
<h2>Heroic.AutoMapper Now Supports Everything!</h2>
<p>You can now use <code>Heroic.AutoMapper</code> with ASP.NET MVC 5, ASP.NET Web API, ASP.NET Core, console applications&#8230; whatever you want. There is no longer any dependency on ASP.NET or any of its infrastructure.</p>
<p>If you want to use <code>Heroic.AutoMapper</code> with ASP.NET Core, you can call it from your <code>Startup</code> class, like so:</p>
<pre><code class="language-csharp">using Heroic.AutoMapper;

namespace YourNamespace
{
    public class Startup
    {
        //.. snip

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseCors(x =&gt; x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());

            app.UseAuthentication();

            app.UseMvc();

			HeroicAutoMapperConfigurator.LoadMapsFromAssemblyContainingTypeAndReferencedAssemblies&lt;WidgetModel&gt;();
        }
    }
}
</code></pre>
<p>Want to use it in a console app? You can use this:</p>
<pre><code class="language-csharp">using Heroic.AutoMapper;

public class Program 
{
	public static void Main() 
	{
		HeroicAutoMapperConfigurator.LoadMapsFromCallerAndReferencedAssemblies();

		Console.WriteLine("All set!");
	}
}
</code></pre>
<h2>Give It a Shot!</h2>
<p>Installing this new version is easy:</p>
<pre><code>dotnet add package Heroic.AutoMapper --version 5.0.0
</code></pre>
<p>Or</p>
<pre><code>Install-Package Heroic.AutoMapper -Version 5.0.0
</code></pre>
<p>If you run into any problems, please let me know on the <a href="https://github.com/MattHoneycutt/HeroicFramework/tree/master/Heroic.AutoMapper">Github repo</a>!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.trycatchfail.com/2018/05/09/heroic-automapper-for-net-core-released/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Easy Angular Notifications with ASP.NET Core</title>
		<link>https://www.trycatchfail.com/2018/04/23/easy-angular-notifications-with-asp-net-core/</link>
					<comments>https://www.trycatchfail.com/2018/04/23/easy-angular-notifications-with-asp-net-core/#disqus_thread</comments>
		
		<dc:creator><![CDATA[Matt Honeycutt]]></dc:creator>
		<pubDate>Mon, 23 Apr 2018 22:54:03 +0000</pubDate>
				<category><![CDATA[asp.net core]]></category>
		<category><![CDATA[angular]]></category>
		<guid isPermaLink="false">https://www.trycatchfail.com/?p=1445</guid>

					<description><![CDATA[Displaying feedback to your users is one of those common, cross-cutting (boring!) requirements that should be baked in to your application&#8217;s framework. That&#8217;s just as true with old-school ASP.NET MVC as it is with ASP.NET Core and Angular. In this post, I&#8217;ll show you how you can bake this capability in to a modern Angular...]]></description>
										<content:encoded><![CDATA[<p>Displaying feedback to your users is one of those common, cross-cutting (<strong>boring</strong>!) requirements that should be baked in to your application&#8217;s framework. That&#8217;s just as true with old-school ASP.NET MVC as it is with ASP.NET Core and Angular. In this post, I&#8217;ll show you how you can bake this capability in to a modern Angular app with ASP.NET Core on the backend!</p>
<p><span id="more-1445"></span></p>
<h2>What We&#8217;ll Build</h2>
<p>We&#8217;ll take the same approach we did in our <a href="https://www.trycatchfail.com/2018/02/21/easy-bootstrap-alerts-for-your-api-results-with-asp-net-core/">Bootstrap-based notifications</a>. We&#8217;ll decorate our ASP.NET Core action results using an extension method:</p>
<pre><code class="language-csharp">[HttpGet]
public IActionResult Success()
{
    return Ok(new {id = 1, name = "success"}).WithSuccess("It worked!", "All is well...");
}
</code></pre>
<p>Client-side, we&#8217;ll automatically grab the status and display it using <a href="https://jaspero.co/resources/projects/ng-notifications">angular2-notifications</a>:</p>
<p><img decoding="async" src="https://www.trycatchfail.com/wp-content/uploads/2018/04/BlogPostseasy-angular-notifications-with-ng-notifications-and-aspnet-core-02.png" alt="" /></p>
<blockquote><p>Jaspero&#8217;s <code>angular2-notifications</code>: A light and easy to use notifications library for Angular 2.</p></blockquote>
<p>We&#8217;ll only write that code once, so client-side, our normal API calls will be free of any boring, repetitive logic, leaving us with simple, clean code:</p>
<pre><code class="language-ts">async create(form: Widget) {
    const result = await.httpClient.post('/some/api', form).toPromise();
    
    // No need to manually show feedback!
}
</code></pre>
<p>Let&#8217;s get stated!</p>
<h2>Project Setup</h2>
<p>I&#8217;m going to creat a new <a href="https://www.trycatchfail.com/2018/03/22/creating-a-new-asp-net-core-2-1-preview-project-with-angular/">ASP.NET Core 2.1 (preview) project with Angular</a>. I&#8217;ve already fixed the bugs in the template and updated it to provide a better dev-time experience, <a href="https://www.trycatchfail.com/2018/03/22/creating-a-new-asp-net-core-2-1-preview-project-with-angular/">like I described</a>, so check that post if you want more information.</p>
<p>We&#8217;ll also need <a href="https://www.npmjs.com/package/angular2-notifications">Jaspero&#8217;s angular2-notifications</a> package, which we can install with npm:</p>
<pre><code>npm i --save angular2-notifications
</code></pre>
<p>And we&#8217;ll need to import the module in our <code>app.module.ts</code>, along with the <code>BrowserAnimationModule</code>:</p>
<pre><code class="language-ts">//...snip
import { SimpleNotificationsModule } from 'angular2-notifications';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
//...snip

@NgModule({
  declarations: [
    AppComponent,
    NavMenuComponent,
    HomeComponent,
    CounterComponent,
    FetchDataComponent
  ],
  imports: [
    BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
    HttpClientModule,
    BrowserAnimationsModule,
    FormsModule,
    RouterModule.forRoot([
      { path: '', component: HomeComponent, pathMatch: 'full' },
      { path: 'counter', component: CounterComponent },
      { path: 'fetch-data', component: FetchDataComponent },
    ]),
    SimpleNotificationsModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
</code></pre>
<p>The final step is to add the <code>simple-notifications</code> component somewhere that is available globally throughout our app. The simplest thing is to just add it to <code>app.component.html</code>, like so:</p>
<pre><code class="language-html">&lt;div class='container-fluid'&gt;
  &lt;div class='row'&gt;
    &lt;div class='col-sm-3'&gt;
      &lt;app-nav-menu&gt;&lt;/app-nav-menu&gt;
    &lt;/div&gt;
    &lt;div class='col-sm-9 body-content'&gt;
      &lt;router-outlet&gt;&lt;/router-outlet&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;simple-notifications&gt;&lt;/simple-notifications&gt;
</code></pre>
<p>Now we can inject and use <code>NotificationService</code> to display the various types of notifications that are supported:</p>
<pre><code class="language-ts">import { Component, OnInit } from '@angular/core';
import { NotificationsService } from 'angular2-notifications';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
})
export class HomeComponent implements OnInit {

  constructor(private notifications: NotificationsService) {
  }

  ngOnInit() {
    this.notifications.success('Hi!', 'Everything is initialized!');
  }
}

</code></pre>
<p>We&#8217;ll come back and use <code>simple-notifications</code> in a bit. But for now, let&#8217;s see what we need to do server-side!</p>
<h2>Implementing Notification Extension Methods</h2>
<p>Now we need a way to attach a notification to a response before it goes back down to our Angular app. We&#8217;re going to follow the same approach as we took for <a href="https://www.trycatchfail.com/2018/02/21/easy-bootstrap-alerts-for-your-api-results-with-asp-net-core/">our Bootstrap-based approach</a>, but we&#8217;ll simplify it a bit since we aren&#8217;t going to worry about <code>ViewResult</code>s.</p>
<p>Here&#8217;s what our extension methods look like:</p>
<pre><code class="language-csharp">    public static class NotificationExtensions
    {
        public static IActionResult WithSuccess(this IActionResult result, string title, string body)
        {
            return Notification(result, "success", title, body);
        }

        //snip: repeat for the other notification types!
    }
</code></pre>
<p>And our simplified decorator:</p>
<pre><code class="language-csharp">    public class NotificationDecoratorResult : IActionResult
    {
        public IActionResult Result { get; }
        public string Type { get; }
        public string Title { get; }
        public string Body { get; }

        public NotificationDecoratorResult(IActionResult result, string type, string title, string body)
        {
            Result = result;
            Type = type;
            Title = title;
            Body = body;
        }

        public async Task ExecuteResultAsync(ActionContext context)
        {
            context.HttpContext.Response.Headers.Add("x-notification-type", Type);
            context.HttpContext.Response.Headers.Add("x-notification-title", Title);
            context.HttpContext.Response.Headers.Add("x-notification-body", Body);

            await Result.ExecuteResultAsync(context);
        }
    }
</code></pre>
<p>Now we can add a notification to any <code>IHttpActionResult</code> that we return:</p>
<pre><code class="language-csharp">return Ok(new {id = 1, name = "success"})
         .WithSuccess("It worked!", "All is well...");
</code></pre>
<p>Easy enough!</p>
<p>When a decorated action is executed, it will add three headers to the response: <code>x-notification-type</code>, <code>x-notification-title</code>, and <code>x-notification-body</code>.</p>
<p>We just need to process those headers client-side.</p>
<h2>Displaying Notifications Automatically</h2>
<p>So our API responses are going to have some new headers that tell us about the notification to show. We <em>could</em> handle those headers manually, writing code like this each and every time we invoke our API:</p>
<pre><code class="language-ts">    const response = await this.httpClient.get&lt;HttpResponse&lt;string&gt;&gt;(`/api/some/action`, { observe: 'response' }).toPromise();

    const type = response.headers.get('x-notification-type');
    const title = response.headers.get('x-notification-title');
    const body = response.headers.get('x-notification-body');

    if (type &amp;&amp; title &amp;&amp; body) {
      this.notifications.create(title, body, type);
    }
</code></pre>
<p>But that&#8217;s terrible. We don&#8217;t want to waste time repeating that pattern. And we don&#8217;t have to!</p>
<p>Instead, we can leverage implement an <code>HttpInterceptor</code>.</p>
<p>This simple interceptor will do the trick:</p>
<pre><code class="language-ts">@Injectable()
export class NotificationInterceptorService implements HttpInterceptor {

  constructor(
    //The angular2-notification service
    private notifications: NotificationsService,
    ) { }

  intercept(request: HttpRequest&lt;any&gt;, next: HttpHandler) {

    return next.handle(request)
      .do((ev: HttpEvent&lt;any&gt;) =&gt; {
        if (ev instanceof HttpResponse) {
          const headers = ev.headers;

          const type = headers.get('x-notification-type');
          const title = headers.get('x-notification-title');
          const body = headers.get('x-notification-body');

          if (type &amp;&amp; title &amp;&amp; body) {
            this.notifications.create(title, body, type);
          }
        }
      });
  }
}
</code></pre>
<p>And that&#8217;s it!</p>
<p>Our components can remain blissfully ignorant of these status messages:</p>
<pre><code class="language-ts">    const result = await this.httpClient.post(`/api/widget/activate`, {id: 2}).toPromise();
</code></pre>
<p>And our interceptor will take care of displaying them:</p>
<p><img decoding="async" src="https://www.trycatchfail.com/wp-content/uploads/2018/04/BlogPostseasy-angular-notifications-with-ng-notifications-and-aspnet-core-demo01.gif" alt="" /></p>
<h2>Final Thoughts</h2>
<p>So there you have it: the <a href="https://www.trycatchfail.com/2018/02/21/easy-bootstrap-alerts-for-your-api-results-with-asp-net-core/">same pattern I&#8217;ve shown before</a>, but this time in Angular.</p>
<p>If you want to check out the code, the <a href="https://github.com/MattHoneycutt/HeroicSamples.AspNetCoreWithNgNotifications">repository is on Github</a>.</p>
<p>So what do you think? Useful? Not useful? Let me know in the comments!</p>
<p>I&#8217;ve got more Angular and ASP.NET Core content in the works, but if there are specific topics you&#8217;d like to see, please drop me a note, and I&#8217;ll do my best to accommodate!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.trycatchfail.com/2018/04/23/easy-angular-notifications-with-asp-net-core/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
