Introduction

OSGi.NET helps .NET developers to reform and build software systems consisting of individual logical physical modules which are communicating with each others by Service Bus (a combination of pre-defined service interfaces, could add/get/remove specified
service instance) or by extension point/extension (a mechanism that allow one module to publish extra infomations (extension, xml format) to another who subscribes the same topic (same extension ponit name) in oder to extend the subscriber dynamically. Modules
(always called "Bundle") are under the control of OSGi.NET Runtime with life-cycle management (Installed, Resolved, Starting, Active, Stopping, Uninstalled) which is accessble by others when want to start it, or stop it later. All configuration is
simply put in a readable, editable and reconfigurable file, Manifest.xml. Almost supports all types of .NET applications, even MVC (starts from MVC 3). Minimum supporting .NET version is 2.0.

Background

"The key reason OSGi technology is so successful is that it provides a very mature component system that actually works in a surprising number of environments. The OSGi component system is actually used to build highly complex applications like IDEs
(Eclipse), application servers (GlassFish, IBM Websphere, Oracle/BEA Weblogic, Jonas, JBoss), application frameworks (Spring, Guice), industrial automation, residential gateways, phones, and so much more. " --Benefits
of Using OSGi

OSGi.NET, a dynamic modularization framework, which is a .NET implementation tightly based on OSGi specifications from OSGi Alliance, is designed and developed by Xi’an UI Information Technology, Inc., in China, from 2008.

Using the code

What's a Manifest.xml for?

Every Bundle has a Manifest.xml to self-describe as a "Plugin" to OSGi.NET runtime environment, which more or less contains several parts as below:

What's the Bundle's basic description, what's his name, what's the version, wht's the order to start?

Where are the assemblies should be loaded? Does it depend on any other Bundles or any Shared aseemblies form other Bundles?

Optionally: Where is Bundle entry point and exit point when it's started or stopped?

Optionally: Define a Service which can be called by other Bundles with an interface and one of its public sub-class that inherits it

Optionally: Define an Extension Ponit to subscribe a topic that's specified by Point attribute. Well, coming in pairs, define an Extension in other Bundles with same Point attribute to publish extra xml-formatted message

Optionally: Details information of this Bundle about its author, company, category or copyright, etc. if has any

The following example describes the implementation of 3 Bundles ("OSGi.NET.MP3DecoderPlugin", "OSGi.NET.APEDecoderPlugin" and "OSGi.NET.AudioFormatService") or 2 types ( 2 Plugins and 1 Service) which work together with a Host
("OSGi.NET.AudioPlayerShell") to simulate a very simple Audio Player, just outputs the supported media types for choosing and its running status.

Plugins

Let's start with OSGi.NET.MP3DecoderPlugin, check out its Manifest.xml

"Extension" with Point specified indicates this Bundle will Publish the inner XML, that carrys the message what type this Bundle will support and by which decoder class, to Runtime that's ready for Subscribing with this topic by another Bundle.
The decoder class is defiened below

"StartLevel" indicates the starting order of this Bundle, the less means start earlier, minimum is 2, default is 50. Start the Service before any others in order to comsume when it's ready

Another difference between plugin above is "ExtensionPoint" with Point specified that indicates this Bundle will subscrtibe all Extension information of this Point. This definition is not necessary, we can handler the Extention in
code with/without it

This is a Service Bundle but there is no definition about any Service, same reason, we can handler it in code, too

Output

More Fun

Input "stop 4" or "sp 4" (4 is the Id of Bundle OSGi.NET.MP3DecoderPlugin in runtime)
The press key "Enter" in Host application, the MP3 option is gone

Input "start 4" or "s 4"
The MP3 will be back

Stop the Host, and zip the OSGi.NET.MP3DecoderPlugin folder before delete it, that means OSGi.NET.MP3DecoderPlugin will be out of this application.

Here let's demo how to install a Plugin remotely. Asume the path of zip file is "D:\OSGi.NET.MP3DecoderPlugin.zip".
Start Host application, there is no MP3 option
Then in Remote Console Tool, input: i "OSGi.NET.MP3DecoderPlugin" "D:\OSGi.NET.MP3DecoderPlugin.zip" "D:\codeproject.com\OSGi.NET\Demo1\OSGi.NET.AudioPlayerShell\OSGi.NET.AudioPlayerShell\bin\plugins\FormatTypes\Lossy\OSGi.NET.MP3DecoderPlugin"
Show the list and start it
Press Enter in Host, MP3 is back then