Getting started for .NET

Javonet allows you to reference and use modules or packages written in (Java/Kotlin/Groovy/Clojure, Ruby, Perl, Python, JavaScript/TypeScript) like they were created in your technology.

To use the guides both interacting technologies needs to be selected from left-side dropdown lists. Developer's technology is named "I code in" and technology to be called is named "I want to use".

Prerequisites

To call library/package/module from another technology, corresponding runtime has to be installed. See Prerequisites for details about installing called technology runtime.

Javonet is available as a Nuget package which can be downloaded from Nuget public repository or from My Javonet Portal.
For application using .NET (Core) 3.1 or higher use Javonet.Netcore.Sdk Package
For applications using .NET Framework 4.7.2 and higher use Javonet.Clr.Sdk Package.
Package can be installed with Nuget Package Manager:

Install Javonet in Nuget

Or with .NET CLI for .NET applications:

dotnet add package Javonet.Netcore.Sdk -s https://api.nuget.org/v3/index.json

or for .NET Framework applications

dotnet add package Javonet.Clr.Sdk -s https://api.nuget.org/v3/index.json

Get activation key

Use register or log in page to get license key, which is necessary to activate Javonet.

First sample application

Javonet needs to be imported as any other dependency.

using Javonet.Netcore.Sdk; //or using Javonet.Clr.Sdk for .NET Framework apps

Javonet needs to be activated first. Activation must be called only once at the start-up of an application. More about activation in Activating Javonet section.

Javonet.Activate("your-license-key");

As a second step, Runtime Context of the called technology needs to be created. RuntimeContext refers to single instance of the called runtime. Once it is created it is used to interact with called runtime.

var pythonRuntime = Javonet.InMemory().Python();

The simplest use case is to get from target technology a type from a built-in library:

var pythonType = pythonRuntime.GetType("math").Execute();

And then get static field from the type:

var response = pythonType.GetStaticField("pi").Execute();

The returned value needs to be cast to calling technology type and can be used as any other variable:

var result = (double)response.GetValue();
System.Console.WriteLine(result);

To sum up, the whole code snippet looks like:

namespace SampleProgram;
// <Import>
using Javonet.Netcore.Sdk; //or using Javonet.Clr.Sdk for .NET Framework apps
// </Import>
class SampleProgram
{
	static void Main(string[] args)
	{
		// <Activation>
		Javonet.Activate("your-license-key");
		// </Activation>

		// <RuntimeContextCreation>
		var pythonRuntime = Javonet.InMemory().Python();
		// </RuntimeContextCreation>

		// <GetType>
		var pythonType = pythonRuntime.GetType("math").Execute();
		// </GetType>

		// <GetStaticField>
		var response = pythonType.GetStaticField("pi").Execute();
		// </GetStaticField>

		// <GetValue>
		var result = (double)response.GetValue();
		System.Console.WriteLine(result);
		// </GetValue>	
	}
}

The same operation can be performed remotely by just changing the new Runtime Context invocation from in memory to tcp that will create and interact with your any runtime objects on any remote node, container or service that hosts Javonet Code Gateway. This way you can preserve the same logic in your application and instantly switch between monolithic and microservices architecture without the need to implement the integration layer based on web services or other remote invocation methods.

Read more about use cases and software architecture scenarios where Javonet runtime bridging technology can support your development process.