Home  /  Questions  /  Question



50   50
Nov 07, 2011


Making abstractions of .net classes to be able to unit test and constructor inject

Hi

To make it possible to unit test and to use constructor injection I often write wrappers for dotnet classes. Like the ones you find in the System.Web namespace, eg. HttpContextWrapper. I normally write: "public interface ISomeDotNetClass" and "public class SomeDotNetClassWrapper". Then I use the interface to inject with.

As I see it this is to use the Adapter pattern. Some code I have seen use the naming "Facade" for the same purpose. But as I see it, it is better to use "SomeDotNetClassWrapper" or "SomeDotNetClassAdapter". Using the naming "Facade" I think is more proper if you want to extract an interface for a whole subsystem.

What do you think is the best naming convention? "SomeDotNetClassWrapper", "SomeDotNetClassAdapter" or "SomeDotNetClassFacade".

If I want to wrap a static class or a class with static methods is it proper to use the same namingconvention? Lets say I want to make "System.Configuration.ConfigurationManager" abstract. Is the following ok, even if I dont send in an instance of any class in the wrapper instead call the static methods?
public interface IConfigurationManager
public class ConfigurationManagerWrapper

I hope you understand my thoughts. I would like some advise.

Regards Hans