Insert typealias programmatically in Silverlight Unity

Feb 8, 2010 at 11:25 PM

Is there a way to insert typeAlias programmatically?  And have the Silverlight client fetch the right assemblies during runtime?

I am using the Silverlight Unity but I am trying to construct a UnityContainer without referencing the assemblies for the Target type.  In that way, I could have a loose-coupling plug-in model.

This is something that could be achieved via UnityConfigurationSection but I understand that there is no XML support for Silverlight Unity.  So I would like to know if there are any alternatives in Silverlight.

Feb 9, 2010 at 1:21 AM

Unity just uses Type.GetType for type lookup, which triggers the .NET (or Silverlight in this case) type loader. Everything works off type objects. You could play games with the AssemblyResolve event in the desktop CLR, no idea if you can do similar stuff in Silverlight.


Feb 9, 2010 at 7:52 PM

I probably misunderstood the capabilities of typealias.  Is it true then that the Unity dll(either Silverlight or Desktop CLR) does not trigger any dynamic Assembly loading?

If so, then it would imply that for a project that resolves types either via XML using UnityConfigurationSection or via APIs like ResolveType, it is necessary for this project to reference the assembly containing the Target type during build time.

Feb 11, 2010 at 7:04 PM

We simply call Type.GetType, which triggers the CLR type loading (and then assembly loading) process. We don't provide any assembly loading infrastructure, we leave it to the CLR.

If using the API, yes you need to reference the assemblies in order to make the call. If using configuration, the assembly must be available to the CLR loader at runtime. Referencing the assembly is the easiest way to get this to happen as part of a build, but you could use a batch script or deployment tool to drop assemblies into the appropriate spots as well.