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

7 minutes, 12 seconds


Right click “Save as…”

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


Follow the discussion

  • Oops, something didn't work.

    Getting subscription
    Subscribe to this conversation

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.