Category Archives: C#

My 2 Cents on Singleton

The implementation of the singleton pattern is pretty easy. However, despite the simplicity I see often that the pattern is being misused or implemented wrongly. What I’ve seen so far: The implementation is not thread-safe. (coding issue) Tight coupling: The business code/logic accesses a static property of a class in order to utilize the singleton… Read More »

IQueryable vs IEnumerable vs IHaveHeadache

Yes.. this ist just another blog post about IEnumerable and IQueryable. But the topic is quite important and I think it worth discussing about both approaches. Recently I had a discussion with a software architect about the implementation of the repository pattern. The question was: Should the repository return IEnumerable or IQueryable? So let’s do… Read More »

WCF Configuration for Large Data

In one of our projects we had to transfer large data from the server to the client WPF application. In the beginning we had some performance issues. Therefore we decided to do some comparisons between ASP.NET Web API, WCF (with and without protobuf-net). The configuration: ASP.NET Web API WCF (Protobuf) WCF – Protobuf serializer –… Read More »

C# Code Snippet for Unit Tests

After coding unit tests the whole day, I decided to create a nice Visual Studio snippet which helps me to write the test method quicker. I usually structure my unit tests like this: public void Validate_ReturnsFalse_WhenStringIsTooLong() { // Arrange var expectedResult = false; var watheverMock = new Mock<IWathever>(); // Act var validator = new Validator(watheverMock.Object);… Read More »

Entity Framework and Expression Queries

In my current project I had to generate a Entity Framework query based on some search criterias defined in a dictionary. The structure of the dictionary was similar to this example here: var searchCriteria = new Dictionary<string, List<string>>() { { "FirstName", new List<string> { "Darko", "NoName" } }, { "LastName", new List<string> { "Micic", "Müller",… Read More »