Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready - Dependency
- Posted: Sep 11, 2009 at 11:17 AM
- 12,261 Views
Right click “Save as…”
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.
Read the full article at http://msdn.microsoft.com/magazine/ee470637.aspx
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.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?