Dmitry Shechtman's Blog

December 13, 2014

AsyncActivator: Targeting Silverlight

This is an (unplanned) article in a series concerning AsyncActivator, a generalization of the .NET Asynchronous Factory pattern:

  1. Basics
  2. Cancellation
  3. Portability
  4. Silverlight

Dependency injection is quite a complex issue that garners a series of its own.

If you’ve been following this blog, you might have noticed that I’m a bit of a perfectionist. Although my latest article concluded:

Our portable AsyncActivator is now compatible with all platforms we’re aware of, save for legacy (i.e., non-Windows-Phone) Silverlight, which supports neither async/await (out of the box) nor reflection (to our requirements).

that little Silverlight box left unchecked kept bothering me. So with a little extra effort I made Ditto.AsyncInit and (some of) its upcoming child libraries compatible with Silverlight 5.

Now, don’t get me wrong. I’m fully aware of Silverlight’s current status — if it’s of any indication, Microsoft’s Immutable Collections library, released in mid-2013, targets every possible platform (including Xamarin), but not Silverlight.

However, that old dog can be taught the async/await trick, meaning many developers maintaining existing applications could benefit from asynchronous initialization having taken care of. If you happen to be a Silverlight developer with asynchrony in mind, you may find this article useful. Regardless of your plans of using any of the Ditto.AsyncInit components, you might still be interested in some of the challenges I encountered while making them compatible with Silverlight.

(more…)

November 30, 2014

AsyncActivator: Targeting Multiple Platforms

This is the third article in a series concerning AsyncActivator, a generalization of the .NET Asynchronous Factory pattern:

  1. Basics
  2. Cancellation
  3. Portability
  4. Silverlight
  5. Dependency injection

The Problem

Two previous installments discussed an implementation of AsyncActivator, later extended to support cancellation. Today we’re going to make it Portable Class Library (PCL) compliant.

AsyncActivator works great on the full-blown .NET Framework 4.5, but what if we wanted to use it, say, on WinRT?

We’ll start by creating a new Class Library (Portable) project and adding our existing files to it:

  • AsyncActivator.cs
  • AsyncInitBase.cs
  • CancelableAsyncInitBase.cs
  • IAsyncInit.cs
  • ICancelableAsyncInit.cs

Make sure the Silverlight box is unchecked, and it builds without a hitch. However, trying to run our UniversalAnswerService example results in:

Unhandled Exception: System.MissingMethodException: Constructor on type ‘UniversalAnswerService’ not found.

How’s that possible? We didn’t even touch UniversalAnswerService!

(more…)

Create a free website or blog at WordPress.com.