Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready - Host Users Dependency Cycle
- Posted: Sep 11, 2009 at 11:17 AM
- 12,279 Views
Right click “Save as…”
We successfully refactored away Host’s dependency on Settings.Instance by allowing the IoC container to pass Host an instance of ISettings via its constructor. It seems like a simple matter to continue refactoring away Host’s dependencies on the other Singletons, but trouble is brewing just around the corner. The next Singleton we extract is Users.Instance. Following exactly the same procedure as Settings.Instance, we discover a horrible secret - a CircularDependencyException.
Let’s take a look at the constructors for Host and Users:
public Host(ISettings settings, IUsers users) {
customSpecialTags =
new Dictionary<string, CustomToolbarItem>(5);
this.settings = settings;
this.users = users;
}
public Users(IHostV30 host) {
this.host = host;
}
So Host depends on Users and Users depends on Host. Before the refactoring, this dependency cycle wasn’t obvious. The two components are in fact much more tightly coupled to one another than expected. Let’s take a deeper look at Users to find out where this coupling is coming from.
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?