Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready - Dependency

Download this episode

Download Video


Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready –Dependency

As we saw, the Host class delegates to a whole host of Singletons (bad pun intended), including Settings, Users, Pages, Snippets, NavigationPaths, and AuthWriter. Each of these Singletons refers to other Singletons, creating a morass of dependencies. Before we start refactoring Host, we need some tests in place to ensure that we are not breaking anything. Configuration of the application and infrastructure is done by the ApplicationBootstrapper, which we introduced in Part 8. Our tests are going to execute ApplicationBootstrapper.Configure, as shown in Figure 2, and then verify that IHostV30 can be resolved from the IoC container as well as that various Singletons are still configured properly. Note that the IoC is initialized to null after every test to ensure that the tests don’t interfere with one another.

Figure 2 Tests Execute ApplicationBootstrapper.Configure

public class AfterTheApplicationBootstraperIsExecuted {
    public void IHostCanBeResolvedFromTheContainer() {

    public void CacheInstanceIsInitialized() {
        Assert.That(Cache.Instance, Is.Not.Null);

    public void SettingsInstanceIsInitialized() {
        Assert.That(Settings.Instance, Is.Not.Null);

    public void AuthReaderInstanceIsInitialized() {
        Assert.That(AuthReader.Instance, Is.Not.Null);

    public void AuthWriterInstanceIsInitialized() {
        Assert.That(AuthWriter.Instance, Is.Not.Null);

    public void SetUp() {
        new ApplicationBootstrapper().Configure();

    public void TearDown() {

With these tests in place, let’s start refactoring Host to expose its dependency problems.

Other videos from this article

Read the full article at http://msdn.microsoft.com/magazine/ee470637.aspx



Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.