Dependency Frameworks and Parameterized Constructors

April 23rd, 2012 Comments

Most dependency injection frameworks support some kind of object initialization through parameterized constructors. The question is whether or not it’s a good idea to use that feature of DI frameworks.

Consider the following code:
Read more…

MEF: Easily Creating Plug-in Based Apps In .NET

April 21st, 2012 1 comment

MEF (Managed Extensibility Framework) is an awesome framework that allows easily loading types at runtime making your apps plugin-ready.   Using reflection magic, MEF makes it super easy for any app to accept plugins.

Following are 5 easy steps involved in making your app plugin-ready using MEF:

  1. Define an interface for plugins.  This is the interface that each plugin must implement.
  2. Define a metadata interface.  This interface tells your app out of so many plugins which one is the correct plugin for a given piece of functionality.
  3. Define one or more concrete plugin classes.
  4. Decorate each class with some attributes.
  5. In your app write a few lines of code to invoke MEF, and let the magic happen.

Read more…

Finding Distinct Elements In A List(T)

August 4th, 2011 2 comments

LINQ provides a Distinct() method, but in order to find distinct elements in a list of some target class, we must first implement the IEqualityComparer<T> interface in our target class. That’s what Distinct() uses in order to compute whether one element is the same as another element. Implementing IEqualityComparer<T>, however, is not so straightforward as it requires us to override Equals() and GetHashCode() methods. Most of the times if all we need to do is just to find non-duplicated elements in a given list, IEqualityComparer<T> route seems like an overkill. Read more…

Texticize – String.Format on Steroids!

July 1st, 2011 Comments

I just released a new version of open source Texticize. Texticize is an extensible and intuitive object-to-text template engine for .NET. You can use Texticize to quickly create dynamic e-mails, letters, source code, or any other structured/unstructured text documents using predefined text templates substituting placeholders with properties of CLR objects at run-time.

Check it out on CodePlex at Texticize