Welcome Guest, you are in: Login

ScrewTurn Wiki

RSS RSS

Navigation





Search the wiki
»

PoweredBy

About

Nimbus.Module is a .Net library for loading .Net assemblies at runtime. You normally use this to support third party addins/plugins in your application, but it can also be used to design your whole application in a modular fashion. For instance I wrote an IRC client once where all the functionallity, including GUI, was loaded from modules after the application had started.

Nimbus.Module is the third module loading system I wrote. I have designed it to be easy to use. This means no meta-tagging, no complicated concepts or intricate module structure. Just tell it what .dll-files you want to load andwhat interface you want an instance of. It even finds the namespace for you if you don't specify any.

Nimbus.Module has been in use on several projects and comes with unit tests. This meas it works.

License

The binaries and source code of Nimbus.Module is currently released under GPLv3.

Download

Nimbus.Module_0.9_bin.zip Precompiled .Net 2.0 binaries (works with .Net 2.0, 3.5 and 4.0)
Nimbus.Module_0.9_src.zip Source code (Note: Test project is for .Net 4.0)

Versions

Version 0.9 is the initial public release. It has been in use for a long time and is well overdue for a public release. I have however not implemented the AppDomain isolation feature that allows you to load "unsafe" code (like Silverlight protects your operating system while running .Net code). Therefore this unit test will also fail. This is to be expected.

Examples

For me the best way to understand how a library works is usually through code. So I'll keep it simple here. This is the UnitTest for Nimbus.Module.

Nimbus.Module also contains a scheduler that can execute your modules at timed intervals. The example code does not mention any of the functionality.

private ModuleRepository moduleRepository = new ModuleRepository();
 
[TestMethod]
public void LoadAssemblies()
{
    // Create new ModuleRepository
    moduleRepository = new ModuleRepository();
 
    // Load two modules
    moduleRepository.LoadAssembly("Nimbus.Module.Test.TestModule1.dll""TestModule1");
    moduleRepository.LoadAssembly("Nimbus.Module.Test.TestModule2.dll""TestModule2");
 
    // Check that module load count is correct
    Assert.AreEqual(moduleRepository.GetAssemblyNameList().Count, 2);
}
 
[TestMethod]
public void CreateInstances()
{
    // Need to load assemblies first
    LoadAssemblies();
 
    var classInstance1 = moduleRepository.CreateInstanceFromName("TestModule1""Nimbus.Module.Test.TestModule1.TestClass"nullnull);
    Assert.IsNotNull(classInstance1);
 
    var classInstance2 = moduleRepository.CreateInstanceFromName("TestModule2""Nimbus.Module.Test.TestModule2.TestClass"nullnull);
    Assert.IsNotNull(classInstance2);
}
 
[TestMethod]
public void GetClassNameList()
{
    // Need to load assemblies first
    LoadAssemblies();
 
    List<string> list;
 
    // Check that we have TestClass in TestModule1
    list = moduleRepository.GetClassNameList("TestModule1");
    Assert.IsTrue(list.Contains("Nimbus.Module.Test.TestModule1.TestClass"));
 
    // Check that we have TestClass in TestModule2
    list = moduleRepository.GetClassNameList("TestModule2");
    Assert.IsTrue(list.Contains("Nimbus.Module.Test.TestModule2.TestClass"));
 
}
 
[TestMethod]
public void GetClassNameListOfInterface()
{
    // Need to load assemblies first
    LoadAssemblies();
 
    List<string> list;
 
    // Check that we have TestClass in TestModule1
    list = moduleRepository.GetClassNameListOfInterface("TestModule1"typeof(Nimbus.Module.Test.Common.ITestClass));
    Assert.IsTrue(list.Contains("Nimbus.Module.Test.TestModule1.TestClass"));
 
    // Check that we have TestClass in TestModule2
    list = moduleRepository.GetClassNameListOfInterface("TestModule2"typeof(Nimbus.Module.Test.Common.ITestClass));
    Assert.IsFalse(list.Contains("Nimbus.Module.Test.TestModule2.TestClass"));
 
}
 
[TestMethod]
public void SharedObject()
{
    // Need to load assemblies first
    LoadAssemblies();
 
    Common.SharedTestObject sharedTestObject = new SharedTestObject();
 
    ITestClass classInstance1 = moduleRepository.CreateInstanceFromName("TestModule1""Nimbus.Module.Test.TestModule1.TestClass"null, sharedTestObject) as ITestClass;
    Assert.IsNotNull(classInstance1);
    string testString = "Test123__";
    sharedTestObject.ID = testString;
    Assert.AreEqual(sharedTestObject.ID, testString);
    Assert.AreEqual(classInstance1.ID, testString);
 
}


Discussion

{discussion}

ScrewTurn Wiki version 3.0.4.560. Some of the icons created by FamFamFam.