C# Convert date from UTC to EST

Published on Jun 7, 2017 by Jamie Munro

Every now and then I need to convert a date from Coordinated Universal Time (UTC) to Eastern Standard Time (EST).† I always found myself trying to remember "Where did I use this last?".† To avoid asking myself, I have now immortalized it on my blog.

Read more >

Tags: ASP.NET | c# | timezones

How to return a CSV from ASP.NET Web API using C#

Published on May 4, 2017 by Jamie Munro

ASP.NET Web API is a framework that is built upon the MVC (Model View Controller) principal to assist in rapidly building a RESTful API using the .NET framework.


By default Web API makes it easy to return common HTML content types, such as: JSON and XML.† However, it requires a little bit more work to return a CSV using Web API.† Read on to learn how.

Read more >

Tags: ASP.NET | c# | web api | csv

Advanced Automatic Ninject Bindings

Published on Jan 13, 2014 by Jamie Munro

Problem


You have a common interface that is used by multiple concrete classes and you donít want to specify each Ninject binding manually.

Solution


The solution to this problem is very similar to my previous post on Automatic Ninject Bindings because it also leverages the NuGet package Ninject.extensions.conventions.

In this example, letís assume you have a single interface called IService<T>.† This interface contains a generic reference to a class or object (e.g. a database model).† Then you have multiple classes that implement the interface.† E.g. UserService : IService<User>.

With the following line of code, all of your classes that implement the IService interface will automatically bind to the corresponding class:


 ††††††††††† var kernel = new StandardKernel();

 ††††††††††† kernel.Bind(x =>

 ††††††††††† {

 †††† †††††††††††x.FromThisAssembly()

 ††††††††††††††††††† .SelectAllClasses()

 ††††††††††††††††††† .InheritedFrom(typeof(IService<>))

 ††††††††††† ††††††††.BindSingleInterface();

 ††††††††††† });

 

Read more >

Tags: Uncategorized | ASP.NET | c# | mvc | ninject

Automatic Ninject Bindings

Published on Jan 7, 2014 by Jamie Munro

Problem


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.

Solution


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.


 IKernel kernel = new StandardKernel();



 kernel.Bind(x =>

 {

    x.FromThisAssembly()

    .SelectAllClasses()

    .BindDefaultInterface();

 });


Read more >

Tags: ASP.NET | c# | mvc | ninject

Automapper Performance Testing

Published on May 27, 2013 by Jamie Munro

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:
 Mapper.Map<Customer, CustomerViewItem>(customer);
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Ö

Read more >

Tags: Optimization | ASP.NET | c# | automapper

Why the Repository Pattern

Published on May 20, 2013 by Jamie Munro

The Best Way to Prevent SQL Injection

Published on Sep 19, 2012 by Jamie Munro