Fun Friday: Links And Fun for 6/20/2014

Friday, 20 June 2014
  • By
  • Jeff Ammons
  • Tags:
  • Fun Friday
  • ASP.Net
  • Programming
  • Links
  • MVC
  • Async
  • Dependency Injection

Spring Chicken

Oh, Mama! Is that Daddy? Is he in jail? Are you fighting him? We are so confused.
Image from Library Of Congress

This week's links are all about Microsoft programming tools and technology.

I've been heavily Linux, Node and Raspberry Pi for a while, so time for Microsoft links this week.

Async in ASP.NET MVC 4

Async Actions In ASP.NET MVC 4

This is from last year, but a good read. I'm planning a blog post this weekend to go into detail, but if you aren't programming ASP asynchronously, you can't handle very much traffic.

If all goes well I'll have stats and info outlining the problem and helping you avoid some pain. For now read this article about how to write async actions.

Samples, Samples, Samples

Microsoft All-In-One Code Framework

All their samples are belong to us? Something like that.

If you need sample code on a wide range of topics, this site is a good place to look. Microsoft posts samples of code to help with tasks developers have posted in MSDN forums and on social media.

I found this one thanks to Greg Duncan's post Thousands of code samples at your finger tips over at Channel 9.

Dependency Injection in ASP vNext

Dependency Injection in ASP.NET vNext

First what is dependency injection? Is it like Botox?

No, it is a technique for loosely coupling software so that you can swap one module for another as needed without necessarily knowing at coding time which will be used.

Of Mice And Lego

If you think Lego bricks, it helps to understand DI (Dependency Injection).

With Lego bricks you could have red, blue and green bricks that each have 4 pegs.

If you are building and you need a brick with 4 pegs, it doesn't matter which color you pick. They will all fit.

With DI, you write your code in such a way that you snap things together via interfaces.

Lets use pets as an example.

We have cats, dogs and snakes.

Each of these implements the "pet" interface. It needs to eat, it has eyes, and a name.

Cats and dogs also implement the "mammal" interface. They have four legs (among other traits).

Since they all implement "pet" and pets have names, we could write code that assigns names to pets.

We could make a factory object that takes in a pet interface and assigns a name to it.

Now we have code that depends on a factory to name our pets. The Injection part comes in because we could have several different factories that all take in a “pet” and name it, but do so in different ways. We need a mechanism to specify at runtime which factory to use.

One factory could look up a list of names from a database and pick one at random, while another could just randomly put letters together to make gibberish names.

Our program depends on a factory that names pets, but it doesn't need to know which factory it will get. We inject that at runtime.

Get Real!

I know this sounds complicated, and more trouble than it's worth, right? How about a real world example?

Here's a good example. Unit testing a web app.

Let's say we have a web app that uses our pet naming factory.

We want to write a test for our method that calls the factory. We're not testing the factory here, we have other tests for that. We just want to know that our code that gets a pet and hands it to the factory works.

Assuming our factory is the one that uses the database, do we really want to connect to the database and pull back values when we run this test? What if we have 50,000 such tests to run?

With DI, we can make a factory that gets a pet and assigns the same name to each pet. Our test can tell our code to run with the simple, non-database version of the factory. It *injects* the dependency (factory) into our code. Our code doesn't know if it's getting a production factory or a test factory. It doesn't need to know.

Back To The Links!

Oh, yeah. Now that we know what DI is, we can appreciate that the new version of ASP.NET called vNext will have a simple DI framework built in.

The link talks about how you can use it or plug in your favorite DI library.

Oh, and here's the link again so you don't have to scroll way back up there to find it: [Dependency Injection in ASP.NET vNext](

IE Developer Channel

[Internet Explorer Developer Channel](

If you want to play with early or experimental bits for IE, this is the place for you.

The one that caught my eye was the ability to use an XBox 360 controller in a web game written in JavaScript. That's cool!

That's it for this week.

Sorry I ran so long on the bit about Dependency Injection, but I felt the link would be meaningless to anyone who didn't know what DI is or why you might use it.

Have a great Friday and see you next week!