Category Archives: ASP.NET

Practical IoC With ASP.NET MVC 4

Just published my latest Pluralsight course: (IoC MVC 4)

Practical IoC With ASP.NET MVC 4

I had many developers asking about a more practical IoC course that shows how to actually use IoC in a real application, so I created this course.

2013 08 27 10 19 08 thumb Practical IoC With ASP.NET MVC 4

Here is the course description:

At first, Inversion of Control (IoC) is a difficult concept to understand. Even after understanding what IoC is, a developer must learn to apply the concepts of IoC and IoC containers to a real application in order to use it effectively.

In this course, John will show you how to use the Unity IoC container in an ASP.NET MVC 4 application to use dependency injection on controllers, filters, views and more. You’ll start off by learning the basics of IoC containers, how they work and why they are important. As well as, learning about how internally ASP.NET MVC 4 creates controllers and views.

In order to understand practically how dependency injection works (the core function of IoC containers) John will walk you through manually doing dependency injection in ASP.NET MVC 4 using your own custom controller factory.

After you have done things manually, you’ll see how to add the Microsoft Unity IoC container to your MVC 4 application to do dependency injection automatically. Essentially you’ll see how it is able to give us more flexibility and reduce the custom code we need to write.

John then takes things even further by exploring some advanced dependency injection techniques using Unity to inject views and filters. He’ll also cover some of the advanced features of the Unity IoC container.

Finally, you’ll take a tour through some other popular .NET IoC containers and see how to get them working in our ASP.NET MVC 4 application. After taking this course you will be equipped with the skills and knowledge you need to build real applications using Inversion of Control and dependency injection.

An MVC4, iOS And Android App With ServiceStack, Xamarin and C#

A bit late getting this out, but I published a new course for Pluralsight.

An MVC4, iOS And Android App With ServiceStack, Xamarin and C#

This course was really fun to create.  I got to use several of my favorite technologies.

2013 08 19 16 52 05 thumb An MVC4, iOS And Android App With ServiceStack, Xamarin and C#

Here is the course description:

It can be very difficult to build a cross platform application that will work on the web as well as popular mobile platforms like Android and iOS.

In this course, I’ll take you through the complete process of creating an application that works on each of the platforms and uses a REST based backend API to share data and business logic—all using C#.

We’ll start off this course by learning how to build a REST based API using the popular open source framework ServiceStack. I’ll show you how easy it is to get ServiceStack set up and even how to store data for the API using a Redis database.

Next, I’ll show you how to create an ASP.NET MVC 4 application that uses the REST service we built to display it’s data and implement it’s logic. We’ll learn how to use JQuery to make AJAX calls to a REST based API from within our MVC 4 application.

Then, we’ll learn how we can use C# and the .NET framework to build an Android application using the Xamarin tools. We’ll use the same REST API, we created earlier and build a real native Android application that is able to consume that API for implementing its logic and displaying data.

Finally, I’ll show you how to do the same thing for an iOS application. We’ll again use C# to build a real native iOS application with the Xamarin tools and learn how to consume REST based web services from iOS.

So, if you are a C# developer and don’t want to have to learn several other programming languages to build cross platform applications; you’ll definitely want to check out this course. By the end of this course, you’ll have the skills you need to be able to implement an end-to-end cross platform solution complete with a REST based API backend all in C#.

Getting Started With Glimpse In ASP.NET MVC

If you are using ASP.NET, especially if you are using ASP.NET MVC, you need to be using Glimpse.

I’m currently working on a more exhaustive Pluralsight course on Glimpse,  (the course is now live!) but I thought I’d write up a quick getting started tutorial here.

What is Glimpse?

Perhaps you haven’t heard of Glimpse yet, or you are just a little unsure of exactly what it is.

Glimpse is basically an open source and free diagnostics platform for the web.  Right now it works best with ASP.NET and especially ASP.NET MVC, but it can be extended to other platforms as well.  There is already work started for a PHP version and even a Python port.

What Glimpse essentially does is let you see diagnostics information about what is happening on your server directly in your page through a small diagnostics window completely rendered in JavaScript.

Out of the box, Glimpse can show you all kinds of information about your MVC application, like what routes are registered, what the flow was through the MVC pipeline and how the models were bound.

(BTW, if you are looking to brush up on your ASP.NET MVC 4 skills or learn about ASP.NET MVC 4, I recommend Professional ASP.NET MVC 4.  Great book, top notch authors.)

Here is what the Glimpse window looks like on a page.

Home Page   My ASP.NET MVC Application   Google Chrome 2013 05 19 09 30 58 thumb Getting Started With Glimpse In ASP.NET MVC

Glimpse is also fully extendable.

There are already plugins for Entity Framework, NHibernate, Ninject and many, many more

The best part about Glimpse is how easy it is to get setup.

I’ll walk you through the steps below.

Step 1: Get Glimpse from NuGet

All you have to do to get Glimpse installed is simply either:

  • Open up the Package Manager Console and type “Install-Package Glimpse.Mvc4” (or “Glimpse.AspNet if you aren’t using MVC)
  • Or, right click on your references, select Manage NuGet Packages, then search for Glimpse and find the appropriate Glimpse package.

GlimpseTutorial   Manage NuGet Packages 2013 05 19 09 44 14 thumb Getting Started With Glimpse In ASP.NET MVC

One you’ve done that, Glimpse will automatically add a few entries to your web.config for you.

2013 05 19 09 46 18 thumb Getting Started With Glimpse In ASP.NET MVC

2013 05 19 09 47 06 thumb Getting Started With Glimpse In ASP.NET MVC

2013 05 19 09 49 21 thumb Getting Started With Glimpse In ASP.NET MVC

Step 2: Turn on Glimpse

Turning on Glimpse is super easy.

Just launch your app and navigate to glimpse.axd.  Then, click “Turn Glimpse On” to set a cookie that will tell the Glimpse component running on the server to send you Glimpse data.

2013 05 19 09 52 16 thumb Getting Started With Glimpse In ASP.NET MVC

Go to glimpse.axd

Glimpse   Configuration Page   Google Chrome 2013 05 19 09 52 38 thumb Getting Started With Glimpse In ASP.NET MVC

Turn it on!

It’s that simple!

Step 3: Fire it up

Now all you have to do is navigate to any page in your application and you’ll see this little icon at the bottom right hand corner of the screen:

2013 05 19 09 55 28 thumb Getting Started With Glimpse In ASP.NET MVC

If you click the icon, you’ll see the Glimpse panel, which currently looks similar to the Chrome Dev Tools panel.

Home Page   My ASP.NET MVC Application   Google Chrome 2013 05 19 09 57 54 thumb Getting Started With Glimpse In ASP.NET MVC

Using Glimpse

Each tab contains different diagnostics information about your application.

This data can be extremely helpful in troubleshooting problems and learning about exactly what is going on inside of MVC.

You can also find plugins that can be easily installed from NuGet.

For example, if you add the Entity Framework plugin, you’ll start seeing a tab that shows data about EF queries, like this:

2013 05 19 10 04 46 thumb Getting Started With Glimpse In ASP.NET MVC

I’m pretty excited about Glimpse and its future.  Anthony van der Hoorn and Nik Molnar, the two creators and main maintainers for Glimpse, have done an excellent job transforming how we get diagnostics information for web applications.

One of the things I find most exciting about this platform is how easy it is to extend.  In my upcoming Pluralsight course, (the course is now live!) I walk you through creating a Glimpse plugin, which is surprisingly easy.

So if you haven’t checked out Glimpse, what are you waiting for?  Go do it now, it will take you about 5 minutes to get setup.

What do you think?  Are you using Glimpse already?  Post a comment and let me know.

My YouTube video for the week: (This is not an ad!)

Dealing With Burnout

And here is the weekly Get Up and Code episode:

Late to the JQuery Party

You may be wondering what happened to my usual Monday post.

Well, I was having my head rearranged by JQuery.  I have to admit, I am pretty late to the party.  I haven’t really been using JQuery at all the past few years.

I missed a lot.

jquerylogo png thumb Late to the JQuery Party

Goodbye type safety

This part scares me a little bit.  I already made a few typos that were pretty hard to detect.

Debugging javascript is not much fun considering that data and methods are both first class citizens.

But, the trade-off just might be worth it.

What we are losing in type safety, we are making up for in productivity and speed.  It is really fast to manipulate a page using JQuery and to hook up events.

I still wish there was some way to have some sort of type safety when using JQuery or Javascript in general, but it really hurts my brain to try and think about how that would be possible.

Perhaps some kind of Script# / JQuery bastard child?

I know some people are doing Javascript unit testing.  That would certainly make me feel safer not having type safety.

Functional thinking

I like the functional thinking paradigm.  One of my co-workers was saying that he likes JQuery because it helps him to write Lamba expressions and LINQ queries.  I tend to agree with him.

I’ve said it before, but I believe the next high abstraction of programming is thinking functionally.

So many pieces of code that I would have used code generation to produce in the past, I can now produce with Lambda expressions.

It’s not all roses

I do have some major issues with JQuery and Javascript in general.  One of the big problems is that JQuery is not a language, and it’s not a library.  It is a DSL built on top of a language.

Bleeding all the way through the stack

The downfall of this is that it is a very leaky abstraction.  Abstractions are good because they allow us to think at a higher level.

Leaky abstractions are bad because they force us to context switch from a higher level of thinking down to a lower level.

In order to understand JQuery you must understand Javascript, the DOM and CSS to some extent.

Think for a second about all the “languages” or technologies you have to know to develop an ASP.NET web page using JQuery and MVC.

  • HTML
  • C# or Visual Basic
  • JSON
  • Javascript
  • JQuery
  • CSS
  • Web Services / Rest
  • HTTP (You need to be able to debug all the coolness you are flinging back and forth.)

When you have it all working, it is pretty slick.  Very slick indeed, but it is not a sustainable model.  It is complex and sprinkled with errors and gotchas.

Debugging / readability

When I am writing JQuery, although I feel like it is magical and cool, I also feel a little bit dirty.


Well, as clean as you try to write JQuery code, it can be pretty nasty.  There is a lot of magic going on and it is not very easily understandable.

Perhaps I’ll get better at expressing my intent clearly in JQuery code, but I am pretty sure it has to due in part with the leakiness of the abstraction layer, and that can’t really be cleaned up easily.

Debugging is also hell.  I tried debugging through the validation library to see why my error messages weren’t showing up, and it was no picnic.

Javascript itself is notoriously difficult to debug because objects can have methods dynamically added to them and all the other little tricks make it hard to look at a watch window and get anything useful out of an object.

View logic

One of the things I really enjoyed while writing JQuery code was putting the view logic where it really belongs.  It is nice to have a language and a server separating the view logic from the model and presentation.

JQuery really allows you to put all the code that manipulates the view in one place, and on the client side, where it really belongs.

JQuery will make your HTML code so much cleaner and helps to actually plug the leaks in the HTML abstraction layer.  (Although it isn’t perfect, especially when working with ASP.NET Web Forms.)

Better late then never at all

So I know I’m really late to the JQuery party, but I’m here now and I am liking it.

Overall, I’d recommend taking a look at JQuery if you are like me and hadn’t really used it until now.  It definitely is a valuable skill to develop and is growing at an extremely rapid pace.

C# vs Java Part 2: Web Platforms

Web platforms are a critical thing to consider any any modern software development environment.

Back in the C++ days it wasn’t about the platform at all.  It was all about knowing the intricacies of the language and pointer manipulation.

Modern programming languages are more about platforms and libraries than about the language themselves.  In both Java and C#, knowing what libraries are available and how to use them is a much more important factor than knowing all the features of the language.  A developer who understands the platforms and base class libraries will be able to accomplish more than a language expert, which is a stark contrast to how programming used to be.

One more note before I dive into the web platforms.  When I use the term platform here, what I am really referring to is the technology platform, base class libraries, and frameworks in general.

The Web


For a long time Java has been dominating web platforms.  If you are doing basic Java web development you will most likely be using Java EE 5 or Java EE 6 which used to be called J2EE.  Aside from that commonality, the rest is a very big question mark.  Here is a list of 10 popular frameworks for developing a Java EE application.

Java web frameworks are huge, cross-cut many different concerns and the choices are daunting, but they are also very good.  For a long time while the .NET community was dragging and dropping controls onto a .aspx page, the Java community was building highly scalable model view controller (MVC) frameworks with distinct separation of concerns.

Most Java web application frameworks are built on top of the basic framework available in Java SE, specifically around applets and beans.  The current generation of the base Java SE specification has been greatly simplified to make writing enterprise web applications much easier than it was in the past.  This is the point where the platform and tooling overlap a little bit.  After selecting a web framework for developing in Java (which pretty much all of them are MVC of some sort), if you have a tool which supports developing on that framework (IDE plugin), development on that framework can be very easy.

Here is the difficulty… information overload.  If you took a look at that list of Java web frameworks, you can see there are many of them to chose from, and each one requires pretty extensive research to understand.  Some of them even combine, like Struts + Spring.  In fairness though,  part of the proliferation of frameworks is due to the age of the platform.  If you can wade through the choices, and settle on a framework, most of the good ones are really good and proven.


ASP.NET for a long time was analogous with Web Forms.  Up until the release of ASP.NET MVC the only way to do C# web development was with ASP.NET Web Forms.  This technology was not bad.  It just did not have enough guidance.  It truly is amazing how easily you can drag and drop a control onto a page and have it automatically populated with data from your database and allow edits to that data all without writing a line of code.  Amazing, but in a ‘violate all separation of concerns, mix all my layers together,  look! I’m accessing the database directly from the UI’ type of way.

Now don’t get me wrong here.  I’m trying to be fair and honest, and Java took a beating in my previous post about languages; ASP.NET Web Forms is going to take one here.  With that said, yes, it is possible to write a good separation of concerns MVC style application using ASP.NET Web Forms.  And yes, it is possible to write an ASP.NET web forms application that properly uses business objects that use the data access layer and still bind the business objects or data transfer objects to the UI.  Before MVC was around, I built several ASP.NET applications which did exactly that.  The problem is that you really had to figure out creative ways to do it, and there wasn’t any kind of real guidance.  I always felt like the platform was trying to push me into dragging and dropping, like a little devil sitting on my shoulder saying “but it is so much easier to just bind that control directly to the database.  Look, the wizard will do it for you.”

Fortunately that problem has been solved with the ASP.NET MVC platform.  It is very new and still needs some maturing, but it encourages good design practices that separate the concerns.  Under the covers it is still using the Web Forms view engine as a default, but that can be swapped out with any number of view engines which are starting to pop up.  There still is a bit of a complexity issue with ASP.NET MVC in my opinion, especially in regards to AJAX.  I know that some of this has been solved, but some people will find it very difficult to come from a platform where you could drag and drop a server control, have a wizard to set it’s properties, and have the HTML automatically generated for you, to one where you have to hand code much of the HTML.  ASP.NET MVC uses HTML helper classes to help render the HTML for you, which is a good step, but I think it still has some room for improvement.

Microsoft has also done an excellent job of getting information out there about how to develop in ASP.NET MVC.  This is one of the areas where MVC shines.  When I go to search for how to develop on Swing or Struts there are some tutorials, but nothing like the volume of information that is out there and easily accessible about ASP.NET MVC.

Rich Internet Applications (RIAs)

Quick blurb on this topic.  .NET and Java both have competitors to Adobe Flex and Air in this space: Silverlight and JavaFX respectively.  There really isn’t even a competition here between Silverlight and JavaFX.  JavaFX does not have a visual design and has some strange new language to learn which mixes layers of abstraction.  Silverlight gives you the full power of the .NET framework and uses a common design with Windows Presentation Foundation (WPF) through XAML.  I am not sure what Sun was thinking here.


It is very hard to compare the web platforms, without giving so many details about them.  I really haven’t even gone into very much depth at all.  Java EE has a much larger web platform, but it is also more fractured.  ASP.NET is only split between two technologies, but the MVC platform is not very mature at this point (although it is growing and improving extremely fast.)  One consideration as a developer is specialization.  It is not possible to be an expert in every single web platform or framework.  If you going the Java route, you’d better pick carefully, because the nature of open source development leads to many dead projects.  A considerable investment in learning could be lost.  ASP.NET MVC is still a gamble at this point, but I think it is a good one, because Microsoft is devoting a large amount of resources to it and the adoption seems to be widespread.

To be continued…

I thought I was going to be able to cover more than the web in this post, but I didn’t realize how much there is about the web platform.  Tomorrow we will look at C# vs Java when it comes to desktop development, and future sections will cover IO operations, databases and concurrency, and mobile.