It’s been a few months since I dropped the Azure SDK on my desktop and the tooling and changed considerably to say the least. The portal changed a bit as well, but once you get used to it, it just works for you, and unlike before you can see everything that’s going on “up there” at a glance.
However, back in the IDE, particularly inside the code there are more pieces that are supposed to bolt up to your Azure code. And if you’re using an MVC 4 web role you can push in a NuGet package called Unity.Mvc4 with comes with the this handy little bootstrapper you can use to load your Unity container using the UnityConfig class that runs next to the bundler and routing configs in the App_Start folder.
This was one thing that I didn’t realize was new to the MVC 4 scaffolding. These config classes help keep things we’ve piled into the Global.asax for a long time. And the UnityConfig class follows suit nicely.
The idea with the bootstrapper is to help keep the type mappings contained, but loading when the app domain spins up each time. All of the other pieces appear to act the same, i.e. life-time management, aliasing, and child containers.
The last thing I’ll mention about things fitting together is when I started this solution months ago, I was using a previous version and the upgrade wizard didn’t fire-up so I didn’t get a bump on my web role “and that’s when the fight started”.
If you’re trying to preserve your old solution and you’re trying to get it to act like an MVC 4 template, don’t. If you don’t get the version bump from the IDE, stop. Create (or add) a proper MVC 4 project from the project template dialog and go from there. Copy your code to the new one, fix up the usings and references and keep going.
While I was doing this refactoring and sorting out my existing unit tests the code started to thin out and I realized that the MVC 4 bits could do what I was making the older MVC project do. It just took a bit of frustration and brute force to recognize this and keep coding.
I had the unique pleasure of deleting a lot of code, and still have everything work, well. Just had to sync with the tooling and the way things are supposed to fit together now. Same tools, just a different approach sometimes when the bits are out in front of the IDE. Not a bad thing, just different, and better.
*** Update ***
So I didn’t need the UnityConfig class anyway. The NuGet step actually plugged the bootstrapper into the root of the website and exposed a static RegisterTypes(IUnityContainer container) method that handles the mappings. I usually don’t wrap my type registrations in code, but rather in the configuration file so I can easily add types on the fly. The bootstrapper exposes a static method that handles returning the container. Here’s a code snippet with one registration added.
.
HTH /oFC
You must be logged in to post a comment.