I often find myself using this great C# function: string.IsNullOrEmpty. It is the assured way to confirm whether a string is empty – null or otherwise. However, I often find myself wanting to know when it is not empty, so I wrote an string extension named HasValue.
Tag: c#
-
Advanced Automatic Ninject Bindings
You have a common interface that is used by multiple concrete classes and you don’t want to specify each Ninject binding manually.
-
Automatic Ninject Bindings
You have a large project with many interfaces and many different concrete implementations. Because of this, managing every single Ninject binding is becoming challenging and time consuming.
By leveraging an additional Ninject NuGet package called Ninject.extensions.conventions, you can write a single line (wrapped over several for readability 😉 that will manage all of your Ninject bindings.
-
Automapper Performance Testing
I hate typing more lines of code then I need to; especially something as simple as mapping a domain model to a view model. Enter Automapper!
By performing a one-liner: [code] Mapper.Map<Customer, CustomerViewItem>(customer);[/code] I can quickly map my domain models to my view models.
I was recently reviewing an old article on CodeProject: http://www.codeproject.com/Articles/61629/AutoMapper that contains a quick and easy demo. Inside this article, it discusses performance and it indicates that Automapper is 7 times slower than manual mapping. This test was done on 100,000 records and I must say I was shocked.
My first thought is this requires more testing. Especially since 100,000 records is a lot. In most scenarios I would estimate my largest mapping might be 1,000, but even 1 would probably be a very regular use-case. Let’s put it to the test…
-
Why the Repository Pattern
After the incredible reaction to a recent blog post, Entity Framework Beginner’s Guide Done Right, I feel like before writing some more code to further the basic example, I’ll take a step back and explain my beliefs in the repository pattern.
I was really overwhelmed with the reaction; what started with a simple 30 minute blogging effort has turned into something absolutely incredible. The original post was really a starting point about not placing direct querying and saving to the database mingled with the core code.
Please note, these are my thoughts on the pattern based on current and previous pain points that I’ve/am experiencing and I’d love to hear others input in making things better.