MEF – Thread Safety and GetExportedValue

January 2, 2011

In one of our projects, we encountered odd exceptions that were thrown out of “GetExportedValue<T>” from the CompositionContainer of MEF. There are 2 exceptions that I have seen that are related to the same issue: System.InvalidOperationException: GetExportedValue cannot be called before prerequisite import 'MyType..ctor(Parameter="myParameter", ContractName="MyOtherType")' has been set System.ArgumentException: An item with the same key has already been added. After digging into the matter, we found that these errors occurred while trying to call GetExportedValue concurrently from numerous threads. Yeah, simple as that, MEF isn’t thread-safe in its default form. Following is...
tags: ,
37 comments

TechEd 2010 Eilat – Great so far

November 29, 2010

 I decided to blog alittle about my ongoing experience here in TechEd Eilat.Yesterday, on day 1, I arrived to Eilat and immediately got the great atmosphere this conference has put out for us.Day 1I attended the evening key-note session and was very impressed by the operation the Microsoft has gathered and pulled it off beautifully. It wasn't hard to see that there was a great investment in this conference, and I'm simply glad.The key-note was refreshing with good entertainment. There wasn't much that came new to me, but it was certainly nice to see how Microsoft sees the next...
no comments

Cost-Oriented Development

November 27, 2010

With the emerging of cloud computing, our perception of software design needs to shift and take account for the affects we need to deal with. The signs are clear, with investments of billions of dollars by leading companies, such as Microsoft, Google, Amazon - Cloud computing is the future of the IT industry and many other specific product companies that can leverage its benefits. If you looked into it, you must know by now – the pricing models for hosting applications in the cloud varies and you can choose from different packages to meet the...
no comments

TechEd Eilat 2010

November 23, 2010

I’d like to thank Michal and Microsoft for sending me to the TechEd in Eilat next week. There are some presentations which seem cool and I’m happy to get the chance to hear them out in person. I plan to blog about interesting sessions, so tune in if you like.
one comment

WCF – TCP with UserNameToken without Message Security

November 7, 2010

There was a project that I assisted with the WCF communications where they needed to allow the client to specify different credentials without being dependent on the windows account. The first thing that comes into mind is to use the UserNameToken technique to pass in the client credentials. The design instructed to use TCP as the transport and not use message security. Obviously, this technique has privacy and integrity issues where there isn’t any encryption nor signing, but that was their decision because it wasn’t an issue in the purpose of the project. Well, this setting isn’t...
tags: ,
4 comments

MEF – Conventional catalog for registering non-attributed parts

October 18, 2010

As part of the task where I had to upgrade an existing WPF project to PRISM 4.0 and work with MEF, one of the requirements was to support registering existing non-attributed parts. Consider the following example - Code Snippet public interface IFoo { }   public class Foo : IFoo { }   static void Main(string args) {     //This is the desired thing to do     myCatalog.Register<IFoo, Foo>(); } As you can see, type Foo has no export definitions set on it. One...
tags: ,
no comments

MEF – Runtime Type Catalog, support multi registrations in runtime

October 17, 2010

Recently, I dug deep into MEF because I was involved in a project where there was a decision to upgrade the WPF client to PRISM 4 and advance to using MEF alone instead of Unity. While many argue that MEF isn’t yet a full DI framework, it still provides an easy way to enable application extensibility in your projects. One of the tasks that I had while upgrading the client to PRISM 4, is to keep supporting type registration in runtime, something in the sort of the following - Code Snippet ...
tags: ,
no comments

Localize DayOfWeek Enum

October 12, 2010

If you have a DateTime and you would like to get the localized name of the day according to the current culture, you can just do the following - myDateTime.ToString(“ddd”); I had a different scenario though, I had an object with a property of DayOfWeek enum which represents week days. I needed to display just that property in my UI as a localized string. In this case, I don’t have a DateTime so I can’t use its culture-based string formatting, so I can’t use the approach written above. ...
tags: ,
2 comments

WPF – ComboView – ComboBox with a TreeView

October 10, 2010

Update 26/09/2011 - There is an issue with the control where the entire tree is loaded, which may affect performance and memory allocation when working with many items. Unfortunately, I don’t think I would be able to fix that any time soon. A few years back, I built a WPF control that I decided to share here now. The control is called ComboView – A ComboBox showing a TreeView inside to display hierarchical data (you can use it for flat data if you need its features though). The control provides some really nice built-in...
tags: ,
19 comments

WCF Contrib – Your own base Client Channel Classes

One of the core components in WCF Contrib is the ‘ClientChannel’ which handles the client side proxy creation and management, allowing you to easily call services, with the addition of environment support, using using, and comprehensive behaviors extensions model. Currently, the built-in Client Channels can be instantiated with a configuration name which it loads the ChannelFactory with. A common question is, how can you use the Client Channel if you like to instantiate the ChannelFactory in code. The way to do that is to inherit from ClientChannel and override ‘CreateChannelFactoryCore’ and just return the ChannelFactory...
no comments