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 →
Category: code
String to byte[]
public static byte[] ToByteArray(this string str) { UTF8Encoding encoding = new UTF8Encoding(); return encoding.GetBytes(str); } Read more →
VSTemplate
Template Parameters codeproject What a palaver you have to go through to get nested items from a VSTemplate. 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 →
Basic MSMQ example
ClassLibrary project public class Command1 { public int id { get; set; } public string name { get; set; } } static string queue = @”.private$Command1Queue”; Client project static void Main(string[] args) { MessageQueue msMq = new MessageQueue(queue); while (true) { var key = Console.ReadKey(); switch (key.Key) { case ConsoleKey.Escape: return; default: string name = “SomeName”; for (int i =… Read more →
MassTransit
How shite can documentation be? Just look at MassTransit. FAIL. this link was a tiny bit useful The following code took a few hours to form – it shouldn’t be so difficult. Why spend an age writing something that looks to be great and then offer little to no help in how to use it? public class Model1 { public… Read more →
More TDD Kata’s
The Bowling Game Kata Gutter game scores zero – When you roll all misses, you get a total score of zero. All ones scores 20 – When you knock down one pin with each ball, your total score is 20. A spare in the first frame, followed by three pins, followed by all misses scores 16. A strike in the… Read more →
SQL Server Maintenance
http://www.sqlservercentral.com/scripts/Backup/62380/ Backup Integrity check Index & statistics maintenance Read more →
TDD – getting started
It’s not TDD, it’s design by example http://stackoverflow.com/questions/2512504/tdd-how-to-start-really-thinking-tdd … I write a test that starts by ‘newing’ up a class that doesn’t exist. It won’t compile. (red) So, I create an empty class so it compiles, and succeeds. (green). I call a method on the class, it doesn’t yet exist and won’t compile. (red) I right click, “generate method”. Compile,… Read more →
SimpleInjector IEnumerable<ISomeService<T>> With A Mixture Of Open & Closed Generics – Further investigation
Please note that as of Release 2.3 of SimpleInjector the features discussed in this and related articles are available out of the box with the new registration method RegisterAllOpenGeneric This post is a follow on from previous posts here and here. I’ve altered the test to return IEnumerable<ISomeService<T>> where T is an interface instead of a class. public interface IClass… Read more →