Cross cutting code
-
I'm currently in the process of refactoring a web app to make it more testable and have posted here about it. I've managed to move forward a lot but now I'm in the situation where I perform the dependency injection on the constructor or via setting properties and the number of items needed is increasing e.g. Membership, state management, meta data provider etc. Although I could look at using static classes within the assembly I need to provide the implementation to be used from outside the assembly e.g. web app creates instance of class providing the relative dependancies and I am also concerned about the testability of static classes. Any suggestions about approaches I could take or patterns I could follow would be greatly appreciated.
-
I'm currently in the process of refactoring a web app to make it more testable and have posted here about it. I've managed to move forward a lot but now I'm in the situation where I perform the dependency injection on the constructor or via setting properties and the number of items needed is increasing e.g. Membership, state management, meta data provider etc. Although I could look at using static classes within the assembly I need to provide the implementation to be used from outside the assembly e.g. web app creates instance of class providing the relative dependancies and I am also concerned about the testability of static classes. Any suggestions about approaches I could take or patterns I could follow would be greatly appreciated.
Some cross-cutting concerns can be aggregated into "context", which is usually globally accessible. Think of HttpContext...you can access it anywhere via HttpContext.Current. Think of context from a grammatical perspective...certain words or phrases only have meaning when they are taking "in context". Same general idea with programming. A piece of code really only works when you factor in the appropriate context(s). Not everything needs to be injected, some things should be globally accessible via one or more contexts. This might help lighten your DI load so that you are only injecting direct dependencies of each class, while keeping global dependencies properly centralized.