This is an angular wrapper of WebAssembly Mono Runtime.
- Add this npm package to angular project
- Configure some settings
- Put .NET assembly to assets
- Call native methods of .NET on client-side
ngx-dotnet requires Angular v6+ to run.
{
"dependencies": {
...
"ngx-dotnet": "0.3.0"
}
}
...
"architect": {
"build": {
"options": {
"assets": [
// Past before all assets
{
"glob": "**/*",
"input": "node_modules/ngx-dotnet/assets",
"output": "assets/dotnet"
},
// other assets
...
]
}
}
}
- Compile netstandard2.0 project as release mode
- Copy *.dll and *.deps.json from 'bin/Release/netstandard2.0' to 'assets/dotnet/bin'
- Copy other dependent third-party assemblies from '.nuget/...' to 'assets/dotnet/bin'
import { NgxDotnetModule } from 'ngx-dotnet';
@NgModule({
...
imports: [
...
NgxDotnetModule
],
...
})
import {
NgxDotnetService,
DotnetPreferences,
DotnetApp,
DotnetMethodBinding
} from 'ngx-dotnet';
constructor(
private dotnetService: NgxDotnetService
) { }
const preferences = new DotnetPreferences(
'assets/dotnet', // Path to mono runtime
'bin', // Directory witn target .NET assemblies (full path 'assets/dotnet/bin')
'DotnetDemo.deps', // Json which contains of the necessary dependencies
// Bindings to public static methods
[
new DotnetMethodBinding('SomeNamespace', 'SomeClass', 'SomePublicStaticMethodName'),
new DotnetMethodBinding('SomeNamespace', 'SomeClass', 'OtherPublicStaticMethodNameAsync'),
...
]
);
interface IDotnetAppMethods {
// Sample synchronous method signature
SomePublicStaticMethodName(parameter: number): string;
// Sample asynchronous method signature
OtherPublicStaticMethodNameAsync(parameter: string): Promise<Array<number>>;
...
}
const dotnetApp = await this.dotnetService.getApplicationAsync<IDotnetAppMethods>(
preferences
);
const text = dotnetApp.methods.SomePublicStaticMethodName(123);
const numbers = await dotnetApp.methods.OtherPublicStaticMethodNameAsync(text);
MIT