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

Download

Right click “Save as…”

  • High Quality WMV (PC)
  • MP3 (Audio only)
  • MP4 (iPhone, Android)
  • Mid Quality WMV (Lo-band, Mobile)
  • WMV (WMV 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

[TestFixture]
public class AfterTheApplicationBootstraperIsExecuted {
    [Test]
    public void IHostCanBeResolvedFromTheContainer() {
        IoC.Resolve<IHostV30>();
    }

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

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

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

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

    [SetUp]
    public void SetUp() {
        new ApplicationBootstrapper().Configure();
    }

    [TearDown]
    public void TearDown() {
        IoC.Initialize(null);
    }
}

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

Tags:

Follow the Discussion

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.