The new project my small company is working on is quite interesting…since this will be our first ‘real’ application developed in .NET 3.5 we evaluated the possibility to develop the whole application as a web application due to the new possibilities offered by the environment.

The hard task is mainly that we need to develop it as a composite application to have the possibility to ‘inject’ new blocks of functionality when the users ask for them, also separate the application in small blocks make our life a little easier.

I will not go into detail of how composite applications works cause you can already find a lot of good sources of information on the web.

Why use Silverlight instead of..lets say Flash? well we made a preliminary check of all the ‘coolest’ feature we needed and we made some simple test projects to see if they could be doable as a web app (it took some time yes), stated that..we made a simple consideration…since we are not yet 100% sure we can make it all (you never know what your users will ask to you in the future) we decided to try Silverlight simply cause if the project is well structured you can easily build a safe WPF application for the UI interaction.

Spoke like that it seems an easy task to do…but believe me it’s not, so the first thing to do is look around for some framework that can you along the way, I knew it existed a ‘Composite Application Guidance for WPF’ from the P&P team (codename PRISM) and some days ago they released new version which start to have Silverlight support too (see for details).

Actually they are introducing multi-targeting…that is structuring the project to isolate the completely the business code from the presentation code so you can easily have multiple UIs for the same application…PERFECT just what I needed…the only drawback is that the whole project still uses SL2B2 :) however I’ll give it a shot for sure to see if it completely fits my needs (hoping to not have to convert too many things).

The second point to note is that a Silverlight application can become quite huge fast and it’s not very good to force the users to download all the modules during the startup (even the ones they do not use or the ones they’ll use at a later time), the first version of composite application for Silverlight (you can still get the source code from Codeplex as a spike from the main project) used the Unity IoC container to obtain the modularity, but didn’t supported the ‘deferred loading and registration of types’. That is you still had to download the whole application at start.

So In the past days I was working on a wrapper over the default Unity IoC Container to add support for delayed download of assemblies and ‘deferred registration of types’, the goal is obtain a generic IoC layer (with the ability to swap the default container, cause sooner or later Spring.NET or Castle Windsor will also offer a Silverlight solution, NInject is also a good project, at that point one will choose the one he loves most) that is able to register Types from already downloaded and available assemblies so the types can be directly created, and to store the registration of types in assemblies that have to be downloaded in some internal structures.

In this way when the code ask for a type the container is not able to create, we start download the related assembly, load it into the runtime, proceed to register the type into the IoC container, and finally we use the IoC to instantiate the type, all the next requests of the same time do not require to download the assembly (or the xap containing it) anymore. All of it it completely transparent to the caller which only ask the Container Wrapper to resolve a type. I call this process ‘deferred downloading and registration’.

A basic version of this IoC wrapper with limited configuration functionality (it’s still too much tight coupled to Unity yet) is ready so expect an article ‘soon’.

In the end I just want to thank the P&P team for their effort and Michael Sync for the porting of Unity to Silverlight.

Related Content