Com.Latipium.Core 2.0.3

The core code for Latipium that provides inversion of control and distributed computing support

Install-Package Com.Latipium.Core -Version 2.0.3
dotnet add package Com.Latipium.Core --version 2.0.3
<PackageReference Include="Com.Latipium.Core" Version="2.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Com.Latipium.Core --version 2.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Latipium Core Framework

The core framework defined a way for modules to interact with each other without having to reference other modules at compile time or runtime.
This way, there can be optional module dependencies and it will prevent many dependency problems.
When using this framework, there should be no dependencies to anything other than this core framework and the .NET Core framework.

Examples

To run this example, clone the repository and run the following:

$ dotnet build Core.sln
$ dotnet run BinFolder Examples/ReadMe/bin/Debug/netcoreapp1.0/
Loading Alternate Module...
Loading Real Module...
Hello, world!
2 + 2 = 4
Is the module actually correct?: True
$ dotnet run BinFolder Examples/ReadMe/bin/Debug/netcoreapp1.0/
Loading Alternate Module...
Hello, world!
2 + 2 = 0
Is the module actually correct?: False

Other examples can also be run in a similar way.

AlternateModuleImplementation.cs

using System;
using Com.Latipium.Core;

namespace Examples.ReadMe {
    [LatipiumExportClass("ModuleTest")]
    public class AlternateModuleImplementation {
        [LatipiumExport]
        public bool IsValid {
            get {
                return false;
            }
        }

        [LatipiumExport("Add")]
        public int AddNumbers(int a, int b) {
            return a - b;
        }

        [LatipiumPriorityMethod]
        public static int DeterminePriority() {
            return new Random().Next(100);
        }

        [LatipiumLoadMethod]
        public void Load() {
            Console.WriteLine("Loading Alternate Module...");
        }
    }
}

This class defined a module that can be loaded in place of ModuleExample, but has a different implementation.
Anything that is a part of the public interface that other modules will call needs to be annotated with [LatipiumExport].
The DeterminePriority() method allows it to randomly choose between this module and the ModuleExample module.

IInterface.cs

using System;

namespace Examples.ReadMe {
    public interface IInterface {
        bool IsValid {
            get;
        }
    }
}

This interface is for the module to be bound to in ObjectExample.
This is just an alternate way than using the dynamic binding for external modules.
If the members in the interface need to be named differently, add a [LatipiumImport(&quot;newName&quot;)] to it.

LoaderExample.cs

using System;
using Com.Latipium.Core;

namespace Examples.ReadMe {
    [LatipiumLoader]
    public class LoaderExample {
        [LatipiumImport("ModuleTest")]
        public static dynamic Module;

        [LatipiumLoadMethod]
        public static void Load() {
            Console.WriteLine("Hello, world!");
            Console.WriteLine("2 + 2 = {0}", Module.Add(2, 2));
            new ObjectExample();
        }
    }
}

This is a loader, so it is where the control enters the program.
The module is automatically imported to the static field Module so that it can be used.

ModuleExample.cs

using System;
using Com.Latipium.Core;

namespace Examples.ReadMe {
    [LatipiumExportClass("ModuleTest", 42)]
    public class ModuleExample {
        [LatipiumExport]
        public bool IsValid {
            get {
                return true;
            }
        }

        [LatipiumExport("Add")]
        public int AddNumbers(int a, int b) {
            return a + b;
        }

        [LatipiumLoadMethod]
        public void Load() {
            Console.WriteLine("Loading Real Module...");
        }
    }
}

This is the real implementation of the module, as opposed to the one in AlternateModuleImplementation.

ObjectExample.cs

using System;
using Com.Latipium.Core;

namespace Examples.ReadMe {
    public class ObjectExample : LatipiumObject {
        [LatipiumImport]
        public IInterface ModuleTest;

        public ObjectExample() {
            Console.WriteLine("Is the module actually correct?: {0}", ModuleTest.IsValid);
        }
    }
}

This is an object that can be constructed normally (not like a singleton like module are) and still has automatic imports.
If the object needed to extend another class, so it could not extend LatipiumObject, just add the following:

        public ObjectExample() {
            LatipiumDependencies.Inject(this);
            Console.WriteLine("Is the module actually correct?: {0}", ModuleTest.IsValid);
        }

Latipium Core Framework

The core framework defined a way for modules to interact with each other without having to reference other modules at compile time or runtime.
This way, there can be optional module dependencies and it will prevent many dependency problems.
When using this framework, there should be no dependencies to anything other than this core framework and the .NET Core framework.

Examples

To run this example, clone the repository and run the following:

$ dotnet build Core.sln
$ dotnet run BinFolder Examples/ReadMe/bin/Debug/netcoreapp1.0/
Loading Alternate Module...
Loading Real Module...
Hello, world!
2 + 2 = 4
Is the module actually correct?: True
$ dotnet run BinFolder Examples/ReadMe/bin/Debug/netcoreapp1.0/
Loading Alternate Module...
Hello, world!
2 + 2 = 0
Is the module actually correct?: False

Other examples can also be run in a similar way.

AlternateModuleImplementation.cs

using System;
using Com.Latipium.Core;

namespace Examples.ReadMe {
    [LatipiumExportClass("ModuleTest")]
    public class AlternateModuleImplementation {
        [LatipiumExport]
        public bool IsValid {
            get {
                return false;
            }
        }

        [LatipiumExport("Add")]
        public int AddNumbers(int a, int b) {
            return a - b;
        }

        [LatipiumPriorityMethod]
        public static int DeterminePriority() {
            return new Random().Next(100);
        }

        [LatipiumLoadMethod]
        public void Load() {
            Console.WriteLine("Loading Alternate Module...");
        }
    }
}

This class defined a module that can be loaded in place of ModuleExample, but has a different implementation.
Anything that is a part of the public interface that other modules will call needs to be annotated with [LatipiumExport].
The DeterminePriority() method allows it to randomly choose between this module and the ModuleExample module.

IInterface.cs

using System;

namespace Examples.ReadMe {
    public interface IInterface {
        bool IsValid {
            get;
        }
    }
}

This interface is for the module to be bound to in ObjectExample.
This is just an alternate way than using the dynamic binding for external modules.
If the members in the interface need to be named differently, add a [LatipiumImport(&quot;newName&quot;)] to it.

LoaderExample.cs

using System;
using Com.Latipium.Core;

namespace Examples.ReadMe {
    [LatipiumLoader]
    public class LoaderExample {
        [LatipiumImport("ModuleTest")]
        public static dynamic Module;

        [LatipiumLoadMethod]
        public static void Load() {
            Console.WriteLine("Hello, world!");
            Console.WriteLine("2 + 2 = {0}", Module.Add(2, 2));
            new ObjectExample();
        }
    }
}

This is a loader, so it is where the control enters the program.
The module is automatically imported to the static field Module so that it can be used.

ModuleExample.cs

using System;
using Com.Latipium.Core;

namespace Examples.ReadMe {
    [LatipiumExportClass("ModuleTest", 42)]
    public class ModuleExample {
        [LatipiumExport]
        public bool IsValid {
            get {
                return true;
            }
        }

        [LatipiumExport("Add")]
        public int AddNumbers(int a, int b) {
            return a + b;
        }

        [LatipiumLoadMethod]
        public void Load() {
            Console.WriteLine("Loading Real Module...");
        }
    }
}

This is the real implementation of the module, as opposed to the one in AlternateModuleImplementation.

ObjectExample.cs

using System;
using Com.Latipium.Core;

namespace Examples.ReadMe {
    public class ObjectExample : LatipiumObject {
        [LatipiumImport]
        public IInterface ModuleTest;

        public ObjectExample() {
            Console.WriteLine("Is the module actually correct?: {0}", ModuleTest.IsValid);
        }
    }
}

This is an object that can be constructed normally (not like a singleton like module are) and still has automatic imports.
If the object needed to extend another class, so it could not extend LatipiumObject, just add the following:

        public ObjectExample() {
            LatipiumDependencies.Inject(this);
            Console.WriteLine("Is the module actually correct?: {0}", ModuleTest.IsValid);
        }

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.3 310 1/3/2018
2.0.2 307 1/1/2018
2.0.1 387 12/31/2017
2.0.0 302 12/23/2017
1.0.3.2 376 12/23/2016
1.0.2.15 275 11/24/2016
1.0.0.17 287 11/23/2016
0.0.18.2 286 11/23/2016
0.0.16.3 355 11/22/2016
0.0.15.6 305 11/22/2016
0.0.14.3 282 11/22/2016