InterAppConnector is a library that helps to create modules that can be easily integrated in different applications and project types by using a common message format.
It is very useful for software or applications that are developed using the modular programming and in particular the module pattern.
You can create one or more modules (called commands) and call them in the same mode without worrying about the project type
- Easy integration and out-of-box experience with console applications
- Integration with web applications, automated and non-interactive procedures (such as batch, jobs, automated tasks, ...) and other project types
- Argument definition in classes. You can define mandatory and optional arguments that are checked before the command starts
- Extensible
- Support for obfuscated code (in preview)
-
Create a class for parameters and name it
SampleArgument
. Add a string property calledName
public class SampleArgument { public string Name {get; set;} = string.Empty; }
-
Create a class for command and name it
SampleCommand
-
Add a
Command
attribute and implementICommand<SampleArgument>
interface -
In
Main
method write your business logic code[Command("hello", Description = "A simple hello command")] public class SampleCommand : ICommand<SampleArgument> { public string Main(SampleArgument command) { return CommandOutput.Ok("Hello, " + command.Name); } }
-
-
Depending on your project type:
-
In a console application, add in your
Program.cs
file inMain(string[] args)
this codeCommandManager command = new CommandManager(); command.AddCommand<SampleCommand, SampleArgument>(); InterAppCommunication connector = new InterAppCommunication(command); connector.ExecuteAsInteractiveCLI(args);
-
In other applications:
-
Parameters must be defined in a
dynamic
object where the name of the properties are the name of the arguments -
Replace
ExecuteAsInteractiveCLI(string[])
method of the example above withExecuteAsBatch(string, dynamic)
methoddynamic arguments = new ExpandoObject(); arguments.Name = "John"; CommandManager command = new CommandManager(); command.AddCommand<SampleCommand, SampleArgument>(); InterAppCommunication connector = new InterAppCommunication(command); CommandResult<SampleArgument> result = connector.ExecuteAsBatch<SampleArgument>("hello", arguments);
-
-
-
Build the project if you have created a console application, otherwise go to step 5
-
In order to get the result
-
If you are creating a console application, open the Command Prompt in Windows or Bash in Linux and type the command below (it is assumed that the project name is called SampleProgram)
SampleProgram.exe hello -name John
You will see a green message with the date and time in current datetime format, the message status followed by the success code and the message
Hello, John
. A typical execution of the program generate the following output:[11/10/2023 23:50:34] SUCCESS (0): Hello, John
-
In other applications, use the object returned by the
ExecuteAsBatch<ArgumentType>
method.
-
For advanced scenarios and in order to learn how to use the library efficiently, see the documentation provided with the library. Below you will find informations about how to find this documentation
The general documentation is available in the GitHub Wiki section.
The InterAppConnector sample code repository contains code examples that shows how to use the library