Month: July 2013

The simplest form of configurable Dependency Injection

public class MyClass { public static Func<string, string> GetConfigValue = s => ConfigurationManager.AppSettings[s]; //… Normal use: string connectionString = MyClass.GetConfigValue(“myConfigValue”); Custom (e.g. Unit Testing) use: MyClass.GetConfigValue = s => s == “myConfigValue” ? “Hi”, “string.Empty”; The simplest form of configurable Dependency Injection Read more →

How to make a custom dependent file in Visual Studio.

From this: To this: Open the .proj file Find the XML that defines these files <Compile Include=”Models\Context.cs” /> <Compile Include=”Models\Client.cs” /> <Compile Include=”Models\Image.cs” /> <Compile Include=”Models\Office.cs” /> <Compile Include=”Models\Policy.cs” /> and add DependentUpon tags <Compile Include=”Models\Context.cs” /> <Compile Include=”Models\Client.cs”> <DependentUpon>Context.cs</DependentUpon> </Compile> <Compile Include=”Models\Image.cs”> <DependentUpon>Context.cs</DependentUpon> </Compile> <Compile Include=”Models\Office.cs”> <DependentUpon>Context.cs</DependentUpon> </Compile> <Compile Include=”Models\Policy.cs”> <DependentUpon>Context.cs</DependentUpon> </Compile> Read more →