Configuration Comparison of Dependency Injection Containers (IOC)

I have often questioned myself which IoC container would be suitable for this or that project best. Their performance is only one side of the coin. The other side of the coin is the simplicity and speed of learning. So, I decided to compare the following containers from this point of view: Autofac, Simple Injector, StructureMap, Ninject, Unity, and Castle Windsor. In my opinion, these are the most popular IoC containers. You can find some of them in the list of the top 20 NuGet IoC packages. Also, I added a few containers based on my personal preferences. I really like Autofac and when writing this article I was reinforced in my choice in most of the cases.

In this article, I will describe the basics of the IoC containers, such as configuration and logging of components. I also want to compare the management of lifetime scope and advanced features. Code examples can be found in the LifetimeScopesExamples GitHub repository.

(more…)

Tricky Questions about C#

Some questions may seem too basic, but they still contain tiny tricks. Sometimes even a simple question may nail to the wall. These questions will be useful to all who study the language.

So, let’s start!

1. What will be the result of execution of the following code?

(more…)

Another Way to Localize Application

I would like to introduce a simple way to localize applications. I do not like the standard mechanism with resource assemblies for the following reasons:

  1. When receiving a value of a localized string in the code, I would like to rely on OOP and compiler prompts. It is very unpleasant to generate a project on Friday evening, and on Saturday morning, to get a call from QAs working overtime that someone inattentive wrote GetResource (“asdf”) instead of GetResource (“assf”). Thus, now something crashes or is displayed incorrectly. In addition, the project is to be “put to print” on Monday… (more…)

Preparing for Exam 70-483: Programming in C#

During preparation for exam 70-483, I found lots of websites containing links to various manuals that helped me a lot. But what really helped me was the memo notes I composed for myself and which I’d like to share in this article. I do not target to provide a detailed description of C#, I just want to refresh your memory and to highlight certain aspects of C#. If you are not familiar with some aspects, it means you have gaps in your knowledge that should be eliminated. (more…)

How Generics save from Boxing

At the method input, we often perform a null test. Someone makes the test as a separate method, so that the code looks cleaner, and gets something like this:

The interesting thing about this test is that I see a frequent use of the object attribute, though you can use generic. Let’s try to replace our method with generic and compare performance.

(more…)

Signals in C#

 

Currently, the thread synchronization in С# causes some difficulties, in particular, when passing synchronization primitives between the objects of your application and supporting them in the future.

The current model with Task and IAsyncResult, as well as with TPL, solve all issues through a proper design. However, I would like to create a simple class that allows sending and receiving signals with a thread lock. (more…)