Extensions made easy: How does it work?

After finding out a cool trick that enables me to install a theme extension using Nuget, I realized that the monster I had created was a lot more powerful.  There was no reason to limit to just theme extensions (Shell extensions work aswell, and hopefully I can research some other extensions soon too…), and there was no reason to limit the installation to just Nuget…

Give me a couple of minutes of your time to show you what I mean…

LightSwitch approach.

The theme extension really has two parts.  One part is responsible for defining the theme (named: theme definition, contained partially in the Common and partially in the Client project), the other part is the actual implementation of the theme (Theme.xaml in my drawing above).

In the awful scheme above, you can see that the LightSwitch application, once the theme is installed and selected, really takes two major steps to load the theme.

  1. First, it uses MEF to find a class that is exported as an “ITheme”.  Basically, it will find the class, and ask it where the implementation can be found.
  2. It will then load the implementation (ie: load the xaml and add it to the application’s resources).

LightSwitch + ExtensionsMadeEasy approach.

What the ExtensionsMadeEasy extension does, is only provide the “EasyTheme”: a theme extension with a definition but without an implementation.

To load a theme, there will be an extra step needed.

  1. First step remains unchanged, the LightSwitch application uses MEF to find a class that is exported as an “ITheme”.  Basically, it will find the class, and ask it where the implementation can be found.
  2. Because the EasyTheme has no implementation itself, it will use MEF to find a class that is exported as an “IThemeExporter”.  Basically, it will find this class, and ask it where the implementation can be found.
  3. The application loads the theme.
Now, this extra step may seem totally ridiculous, but it really offers a totally new range of possibilities: the “IThemeExporter” implementation has been liberated from the original Theme extension, and can be anywhere…  It can be in the Client project of an existing Theme extension (as in the drawing above)…
But it could also be in a Silverlight Class Library, added by a Nuget package.

The advantages are numerous: when the implementation is in a Silverlight Class Library (or a Nuget package), a developer won’t need to reinstall the VSIX extension to see the latest progress of the designer (shell, theme, whatever!) / when you are creating an extension, you can use ExtensionsMadeEasy to debug your extensions with great ease / you can create a new theme / shell / … for your LightSwitch application without MS VS professional / …

Getting started yourself.

Why don’t you give it a go and start developing a theme that can later be used to create a Nuget package, or even your own Theme Extension (VSIX, bah!)?

Advertisements

3 thoughts on “Extensions made easy: How does it work?

  1. Pingback: Extensions made easy: Adding custom commands, global commands and new command groups to the LightSwitch button ribbon. « Jan Van der Haegen's blog

  2. Hi Jan

    Great article. I always enjoy reading your blogs. Please can you confirm how we can change / switch to a different a Theme at runtime using EME or otherwise.

    Thanks

    Dean

    • Hey Dean!
      Switching themes at runtime isn’t really possible. You’d need to download the theme sources and change all the bindings to bind to a property of a static instance, instead of binding to a property :S
      Keep rocking LS!

      Jan

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s