Before I announce the winners, yes it’s plural because it was way too hard to decide one winner, I want to share some great news with all of you. Yesterday I summarized the amount of people that have my book based on the copies that I’ve sold/given away and this number is now above 500 and steadily increasing towards 600!
The feeling I got when receiving my first proof copies of the book is indescribable, it was pure awesomeness and this feeling is almost as great. It makes me very happy that so many developers have decided to get a copy of C# Smorgasbord, thank you all very much for that. All the great feedback and the amount of copies out there are the basis to why I want and can have these giveaways!
Now to the winners, I know that’s why you’re here anyways. As the giveaway was re-published on DZone I’m going to include those comments as well. Thanks everyone that participated and I really hope that if you didn’t get a free copy this time, you’ll enjoy the discounted price found at the end of this post.
The winners are:
Sergio with the following comment:
Checking the content this book has, it would be a good reference to create great architectures using advanced techniques like Reflection or runtime thing creation. It also shows last features of .Net framework so it will have good examples of how to understand them (I honestly can’t understand async :$ and no good Spanish doc, besides that, I have no credit card to buy the book
) I read about the book on this Hacker News’s link: http://blog.filipekberg.se/2012/07/21/c-smorgasbord-will-soon-be-available/
(I said: “I need that book!!”)
Adam with the following comment:
I would like a copy of your book because everything i learn from it will go onto my blog hopefully passing knowledge onto many others.
I feel your book will fill in various gaps in my knowledge, and will hopefully help secure that senior developer position and finally, i mentor the other developers around me and the junior developers, and this book will be an excellent resource, and with titles such as “Creating a challenge out of the trivial tasks” will hopefully help inspire the developers to take pride in even the trivial tasks.
Henric with the following comment:
Don’t leave a former Sigma colleague hanging! I’ll give you a blog post reviewing the book (on my massive 2 visitors a day blog) and I will spread the Smorgasboard love to current co-workers.
Stay awesome!
Daniel with the following comment:
I would like a copy of your book, because I think this would greatly benefit my student project in which we are creating an application where stuff can be augmented and moved / edited with simple gestures
Right now much of the code is hacked together, because no one in the group used C# before (the university teaches java
), what leads to “not-so-good” performance and way too many bugs!
I am responsible for the code quality and C# teaching and the book would help me to be more helpful to the other guys.
Malte with the following comment:
Finished my CS degree last summer, and got a job as a software developer, primarily C#. I try to improve my programming skills every day, and found this blog and blogpost through the “Interesting Finds” blog series from Jason Haley.
Hadn’t heard about your book, but after reading about it, it seems very “hands on”. And i would love to read it.
I find it especially awesome that you self-published the book
Congratulations on winning a free copy of C# Smorgasbord, I hope you enjoy it and help others become better programmers as well!
Now to those of you that didn’t win a free copy. I’ve setup a discount code that can be used on CreateSpace (this is where the book is printed) and this will give you a 35% discount!
Use discount code N9UV3WDP to get 35% off here (takes you to CreateSpace)!
Pssst.. if you don’t want to wait for the printed copy to arrive due to (sometimes) long shipping, you can get the ebook the same day as you purchase the printed copy! Just fill out this form.
Enjoy the read and spread the discount code to anyone and everyone!
?>
Vote on HN
The winner(s) are….
Posted by Filip Ekberg on August 26 2012 1 Comment
Congratulations to the winners!
It was so hard to decide just one winner, so I decided that I will give away 5 books to those that gave me the best reason to!
Here are the lucky winners:
Iris Classon (@IrisClasson)
I should be the lucky winner because I will use the book to spread your knowledge to other developers that really need it.
You know I love questions, and I have many,- and I often look to good books for answers. I hope, and believe, that this book will do just that.
So send me a book, and let me spread some answers! I’ll make sure of course that when the book is used for answers I will provide a link to the book for purchase.
So it’s a win for you, for me, and even more important, for the developers that we can reach
Peter (@clanstyles)
I always love different perspectives on programming and do own quite a lot of books on C# already. I would love to add your book to the list and it received fantastic reviews!
I’m a young student just looking to learn more and if you did happen to choose me as a winner this book wouldn’t go to waste. It’d go right on my desk with the rest of my references after I’ve polished through every page.
Also sharing on Twitter and FB!
Dmitry (@0x49d1)
The book is among not many ones that can show how can i use the primary programming language in a more effective way. From the “about book” section i guess that the book is a mix of Skeet’s “C# in depth” and Wagner’s “Effective C#”. Im willing to constantly improve skills in all and im not going to save money on this book, because using advices from it i will make much more money from work(im sure
) But why not try to win a free copy of the book from its author?..So im in, participating! By the way, thank you for the work. I know that its really difficult to write reasonable tech book.
Kirin Yao (@kirinboy)
After reading the content of this book, I think it’s a great book of C#. I can’t wait to reading it.
I’m a tech book translator from China. I translated several C# books into Chinese, including Jon Skeet’s C# in Depth and Andrew Troelsen’s Pro C# 2010 and the .NET 4 Platform. If the publishing house would introducing this book, I will be happy to be the translator.
Hoping to be the lucky one.:)
Dominic (@nazgjunk)
While I’m going into embedded systems next semester, the introduction courses used C# and I’d like to keep using it for desktop-ish things. Lacking the courses a good book like this – especially when it covers more general subjects as well – would be wonderful
Again, Congratulations!
All the comments have been published, thank you all for participating!
?>
Vote on HN
Win a copy of C# Smorgasbord!
Posted by Filip Ekberg on August 14 2012 35 Comments
C# Smorgasbord is getting great reviews, specially on Amazon UK and to celebrate this I want to give a away a free copy of C# Smorgasbord!
Best of all, it’s the printed copy (which also includes the ebook bundle)!
What you need to do to participate:
- Leave a comment down below with the reason as to why you should be the lucky winner
- Share this post with your friends on twitter:
The best motivation wins and the winner will be notified via e-mail, so be sure to leave your e-mail address when you’re commenting below.
That’s it! Good Luck to you all!

The draw ends September 20 August 26 (6pm CEST) and all comments will be published after that.
The winners have been announced!
?>
Vote on HN
C# Smorgasbord
Posted by Filip Ekberg on August 10 2012 1 Comment
As mentioned in my previous post “C# Smorgasbord will soon be available!” I have been working on a C# programming book.
I am now happy to announce that this book is published and available on CreateSpace and Amazon.com!
Grab a copy and let me know what you think!

It is also available on the following other Amazon sites:
Amazon.co.uk
Amazon.de
Amazon.fr
Amazon.it
Amazon.es
James Sugrue from DZone was able to get early access to C# Smorgasbord and has written an article about it. He also had the opportunity to do an interview with me.
I have gotten a lot of questions regarding the digital copy/ebook, I’m happy to share that the PDF, epub and mobi versions of the book are free if you purchase a printed copy!
If you’ve purchased C# Smorgasbord and are looking to retreive the digital copies, just fill out this form.
The Foreword to the book is written by Kevin Pilch-Bisson who works as a Development — Visual Studio IDE Services for C# and VB.Net. The Foreword is available online and can be read here.
C# Smorgasbord covers a vast variety of different technologies, patterns and best practices that any C# developer should master.
Looking at everything from testing strategies to compilation as a service and how to do really advance things in runtime; you get a great sense of what you as a developer can do. By taking his personal views and his personal experience, Filip digs into each subject with a personal touch and by having real world problems at hand; we can look at how these problems could be tackled.
No matter if you are an experienced .NET developer, or a beginner, you will most certainly find a lot of interesting things in this book. The book covers important patterns and technologies that any developer would benefit from mastering.
Explore your possibilities
Improve your skills
Be Inspired to challenge yourself
Enjoy the read!
?>
Vote on HN
Adapting to Inversion of Control and Dependency Injection
Posted by Filip Ekberg on December 20 2011 11 Comments
You might have come across the phrases IoC, Dependency Injection, Mocking among others, these are commonly used when talking about “Inversion Of Control” which is the full meaning of the abbreviation IoC. So what is this “IoC” that everyone is talking about?
Inversion of control is a principle in Software Engineering, let’s just take a look at the Wikipedia definition of this
In practice, Inversion of Control is a style of software construction where reusable generic code controls the execution of problem-specific code. It carries the strong connotation that the reusable code and the problem-specific code are developed independently, which often results in a single integrated application.
Rather than explaining the text below, let me show an example of an application that does not follow this principle, but will when we’re done here! I’ve got a solution prepared that looks like this:

This solution simulates an order process, where we’ve got a window where we can place some kind of order and then we’ve got some sort of payment provider that executes the order request. This is the only content so far in the InversionOfControl.Payment library:
public enum PaymentResult
{
Success,
Failure
}
public class PayPalPaymentProvider
{
public PaymentResult Execute(string paymentData)
{
if (string.IsNullOrEmpty(paymentData)) return PaymentResult.Failure;
return PaymentResult.Success;
}
}
All we’re doing is to check if the data we send into the execute method actually contains any information at all, if it doesn’t we return a failure result, otherwise we return a success result. Keep in mind that when you implement communication with real payment providers, there are a lot more code to it. But let’s keep the example clean!
The order form is very simple and looks like this:

When we press the button this is what’s going to happen:
private void ProcessOrderClick
(object sender, EventArgs e
)
{
ProcessPayment
(orderInformation
.Text);
}
public void ProcessPayment
(string orderData
)
{
var paymentProvider
= new PayPalPaymentProvider
();
var result
= paymentProvider
.Execute(orderData
);
MessageBox
.Show(result
.ToString());
}
So far we’ve got our order form where we can place an order, when we place the order we execute our order placement and directly communicate with our payment provider. Let’s call this Step 1, we’ve set up the project and we can execute a payment, you can download the code here, unzip it and look in the folder named Step 1. You can also browse the code on github.
Let’s bring up another one of those commonly used abbreviations; TDD or Test After Development. Payments are a great example of something that really needs to be tested thoroughly and you can’t have any errors here. Because either it will be expensive for you, your customer or the end user, no matter which one, you’ve got a big problem.
But what happens when we introduce testing at this stage? How do we actually test the entire flow of the application without communicating directly with payment provider? This is where Inversion of Control and Dependency Injection comes into play. Dependency Injection is a design pattern with the following Wikipedia explanation
DI whose purpose is to improve testability of, and simplify deployment of components in large software systems.
The pattern involves some rules that we need to adapt to, which basically means we have to write cleaner and more testable code. In order to make our code cleaner and more testable we need to break some of the static parts out, this being the actual instantiation of a concrete type in the payment processing.
Take a look at this line of code:
var paymentProvider
= new PayPalPaymentProvider
();
There’s something “wrong” with it; We’re instantiation the concrete type here! To make the method testable, we don’t want that because this means that it will always use our real payment provider information and execute the order against it, which can make the testing expensive for the tester ( if he has to provide is credit card number all the time that is! ).
The easiest way to break it out is to move this to the method argument list, which means that instead of creating an instance in the method, we want someone else to inject it to us. Let’s look at this in a two-step refactoring, first we move the declaration outside of the context and change the method signature:
public void ProcessPayment(string orderData, PayPalPaymentProvider paymentProvider)
{
var result = paymentProvider.Execute(orderData);
MessageBox.Show(result.ToString());
}
This will let us create an instance of PayPalPaymentProvider before we call the processing method and inject it when we call the method. But we are still working with the concrete type, so let’s take a look at the next step in the two-way refactor, let’s simply it to an interface!
All the interface need to tell us is that we’ve got a method called Execute that will return a result to us, so we simply declare it like this:
public interface IPaymentProvider
{
PaymentResult Execute(string paymentData);
}
And then we need to tell our payment provider to actually implement the interface, all we need to change is the class signature:
public class PayPalPaymentProvider : IPaymentProvider
So far so good!
Now we just need to change the method signature for our payment processing as well and we are all set for some DI!
public void ProcessPayment(string orderData, IPaymentProvider paymentProvider)
Now when we want to process the payment when we execute the order, the event handler will look like this instead:
private void ProcessOrderClick
(object sender, EventArgs e
)
{
var paymentProvider
= new PayPalPaymentProvider
();
ProcessPayment
(orderInformation
.Text, paymentProvider
);
}
By the looks of it, we now have a simple and elegant way to process our payments, let’s create a test project and reference to InversionOfControl.Demo. Now create a test called PaymentTests.
So how do we start testing the payment processing?
We only have one concrete payment provider at the moment and this one we don’t want to use for our unit testing, so what we will do instead is that we will create a fake class that will act as the real payment provider, this is dependency injection! So in our payment project, add a new class called FakePaymentProvider and just have it look somewhat like this:
public class FakePaymentProvider : IPaymentProvider
{
public PaymentResult Execute(string paymentData)
{
if (paymentData == "OK") return PaymentResult.Success;
return PaymentResult.Failure;
}
}
Now the test itself isn’t that hard, we’ve already covered the hardest part and that was doing the actual refactoring. So, this is what my test ended up looking like:
using InversionOfControl.Payment;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass
]
public class PaymentTests
{
private IPaymentProvider paymentProvider
;
[TestInitialize
]
public void Initialize
()
{
paymentProvider
= new FakePaymentProvider
();
}
[TestMethod
]
public void OrderFailsWithEmptyInformation
()
{
var result
= paymentProvider
.Execute(null);
Assert
.AreEqual(result, PaymentResult
.Failure);
}
[TestMethod
]
public void OrderSucceedsWithOKInformation
()
{
var result
= paymentProvider
.Execute("OK");
Assert
.AreEqual(result, PaymentResult
.Success);
}
}
I’m initializing my test by creating a fake payment provider and then I am testing if it fails and succeeds as I expect it to, we’ve got a nice way to test our code! This brings us to the next problem, where Dependency Injection and Inversion of Control meet each other, what if I want to test the flow of my application, without actually changing the concrete instantiations everywhere to FakePaymentProvider?
This is where we’re going to bring in a library to help us along the way, but before we do that, let’s just talk a little bit about what is going to happen.
So we’ve got a system that is now refactored so that the important methods that we want to make testable no longer use the concrete types as parameters but rather interfaces that we can implement to create our fake repositories or providers of some sort. The next thing we want to remove completely is the way that we create an instance of our concrete type before we invoke the payment provider.
To do this, we’re going to use a library that let’s us define what kind of implementation to use in runtime. To do this, I’m going to take some help of NuGet to install a library called Ninject. Ninject is an open source dependency injector for .NET and it’s Very good!
Fire up NuGet and let’s start installing those packages!
All you need to write is the following:
PM> Install-Package Ninject
Be sure that you’ve got “InversionOfControl.Demo” selected as “Default project” and you should see something like this:

There are a lot of different type of dependency injectors out there and they act a little bit different. Ninject works like this: you tell ninject what types you want bound to what types or interfaces and then you request these types. There are other dependency injectors that will just replace all interfaces with the concrete type of your choice, but I like Ninject because it gives us an extra type of abstractness and there’s not that much magic to it.
Basically we need to know two things in order to get started with Ninject ( There’s a great Wiki if you want to know more ) first of all, you use something called “Modules” to easily define different types of bindings. For instance, we’re going to create a module that is called PaymentProviderModule. The second thing is that you use something called a kernel to retrieve the concrete types and you tell the kernel which module it should use.
Let’s start off by creating the module:
using Ninject.Modules;
using InversionOfControl.Payment;
public class PaymentProviderModule : NinjectModule
{
public override void Load()
{
Bind<IPaymentProvider>().To<FakePaymentProvider>();
}
}
All we’re saying here is that each time we ask for an IPaymentProvider we’re going to get a Fake payment provider. Now let’s take a look at how this changes the rest of the code! Let’s head over to the order button event handler. The only thing that actually changes now is how we retrieve a concrete type of IPaymentProvider and this is how we do that with Ninject:
private void ProcessOrderClick
(object sender, EventArgs e
)
{
var kernel
= new StandardKernel
(new PaymentProviderModule
());
ProcessPayment
(orderInformation
.Text, kernel
.Get<IPaymentProvider
>());
}
Notice this part in particular kernel.Get<IPaymentProvider>(), we’re actually requesting the interface and not a concrete type! Let’s run the application and see what happens, if we enter anything else than “OK”, we should see a message box that says “Failure”:

And it does!
We’ve successfully made our application less dependent on the concrete type and we’ve introduced testability which we had no way of doing before! The example code for the payment provider is as stated before a bit thin, but in a real world scenario the fake payment provider might not be much bigger than the one we’ve got here, but the real concrete type might.
Now let’s take a look at that definition of Inversion of Control again; it basically means that our application should be able to execute anything against any payment provider without ever having to know about its implementation! We’ve only scratched the surface on how this helps out with testability, there are great frameworks that will help us even more without having to actually create a new concrete type for testing, which in this case was our fake payment provider.
As you might see this is very powerful and gives us a great way to make our applications more testable which will make them more reliable. You can look at the code at the github repository. You can also download the code here.
I hope you found this interesting, if you have any thoughts please leave a comment below!
?>
Vote on HN