Sunday, March 6, 2016

Microsoft.Composition (Portable MEF): Scoping This post is part of mini series, which complete the full MEF series. This post will go over Microsoft.Composition Scoping. What is IoC scoping? IoC scoping is the ability to control the lifetime of registration per specific execution scope. whatever resolved in the scope can resolve it’s item that register under the scope or at its parent container. Classic example for such scope is request. You may want to resolve the same instance again and again within the request scope while keeping it completely isolated from other requests. When supporting this...

Wednesday, February 17, 2016

Microsoft.Composition (Portable MEF): Dependency Injection and Service Locator via Convention This post is part of mini series, which complete the full MEF series. this post will go over Microsoft.Composition Dependency Injection and Service Locator using conventions. in the previous post I describe hot to register types using convention, but in real world types often has their own dependencies which should be satisfies (this is why the IoC process also called composition). In order to satisfy those dependencies you can take different approaches: Dependency Injection constructor-based injection The most common way of passing the dependencies is constructor-based injection where...

Saturday, February 6, 2016

Microsoft.Composition (Portable MEF): Convention This post is part of mini series, which complete the full MEF series. this post will go over Microsoft.Composition conventions. personally I really like convention over IoC, because it’s lead to better consistency of the code-base’s naming. Convention can be simple as the following code:
Code Snippet
var conventions = new ConventionBuilder();
conventions.ForType<Logger>().Export<ILogger>();
conventions.ForTypesDerivedFrom<ISetting>()
.ExportInterfaces(t => t == typeof(ISetting));
var configuration = new ContainerConfiguration()
.WithAssembly(typeof(Program).Assembly, conventions);
using (var container = configuration.CreateContainer())
{
container.GetExport<ILogger>();
}
As you can see the convention can be strict as in line 2,or more general as in line 3,4.the configuration (line 5,6) define the assembly which the convention relate to. convention can be more...

Microsoft.Composition (Portable MEF): Attribute Model This post is part of mini series, which complete the full MEF series. The original MEF series goes over the version shipped with the .NET framework.This mini series will go over the API of 3rd lightweight (yet efficient) MEF version which consumed via NuGet. This version is following the same concept of the previous changes yet some APIshas been changed. Apart of the APIs refactoring (mostly for better)this MEF version is having much better descriptive Exception (it was really bad on previous versions) The down side of this version is lack of documentation.this mini...

Monday, November 11, 2013

ASP.NET Web API + minimal touch MEF this post will offer light touching technique of introducing MEF to ASP.NET Web API. the motivation for having MEF (or any other IoC container) for Web API is for dependencies abstraction and testability. it is also easier to design your API by Contract (mining that you don't have to think about the actual implementation at design time). so why minimal touch? even those other suggestion can be found, most of them involve custom routing. the risk of alter ASP.NET Web API routing, is...

Sunday, February 17, 2013

Immutable Collections Immutability is a pattern which is suit well parallel programming, but you have to be aware of a potential memory pressure risk when it's not implemented right or used wisely. this post will cover a new BCL library (still in its preview stage) which is targeting immutable collections. .NET is already having Concurrent implementation for Queue, Stack, Bug and Dictionary, which is thread-safe, but other type of collection like List is missing. another type of collection are read only collection, but those type...

Saturday, February 16, 2013

MEF 2.0 - mini series: part 8 (Composition options and exception handling) this is the last post in the MEF 2.0 mini series. you can see other posts of this series in here. this post will wrap-up the series with a quick survey to to the to some changes made for the underline composition process. Exception one of the most painful experience of MEF 1 was its misleading exception's description. some time it was really hard to figure out the exception roots. you can read more about MEF...

Thursday, January 24, 2013

MEF 2.0 - mini series: Part 7 (Catalog filter and Deep hierarchic scoping) this is the 7th post in the MEF 2.0 mini series. you can see the following TOC for other posts in this series. in the previous post I was talking about composition scoping and lifetime management. on this one, I will extend the composition scoping topic toward hierarchic along with catalog filtering capability. hierarchic scoping is not trivial, you must understand the hierarchic behavior and what it was design for. MEF hierarchic...

Wednesday, January 16, 2013

MEF 2.0 - mini series: part 6 (Composition scoping and lifetime management) this is the 6th post in the MEF 2.0 mini series. you can see the following TOC for other posts in this series. in this post I will cover a new concept of scoping and part lifetime management, which is a great improvement over MEF 1. MEF 1 was coming with a fairly naïve lifetime management. part's lifetime could be either shared or non-shared (you could also apply 'any' but eventually 'any'...

Tuesday, January 15, 2013

MEF 2.0 - mini series: part 5 (Fluent export properties) this is the 5th post in the MEF 2.0 mini series. you can see the following TOC for other posts in this series. in this post I will cover the fluent property's export. Exporting properties is a less known feature of MEF. MEF 1 was supporting this feature by using the attribute model. you could decorate a property with a attribute and then it become available for imports. the following...