Calling .NET WebAssembly code from views#1526
Conversation
…tvvm into feature/csharp-client
exyi
left a comment
There was a problem hiding this comment.
I find the changes in the framework fine (except for the dotvvm-with-view-modules omission).
It's harder to tell how well will the WASM related code work, It's a bit sad we use reflection to invoke the methods, but I don't see any way around it 🤷
| throw new DotvvmCompilationException($"The type {type} referenced in the @dotnet directive must have exactly one public constructor with one parameter of IViewModuleContext!"); | ||
| } | ||
| // TODO: check parameter type | ||
| return Expression.New(constructors[0], Expression.Constant(null, typeof(object))) |
There was a problem hiding this comment.
| return Expression.New(constructors[0], Expression.Constant(null, typeof(object))) | |
| return Expression.New(constructors[0], Expression.Constant(null, typeof(IViewModuleContext))) |
It won't compile with object.
However, I'm thinking if we want to allow invoking the methods server-side. I guess it makes sense, but passing null into the constructor will just make it fail on the unexpected null reference. Maybe only allow it if the type also has parameterless constructor?
| this.imports = imports; | ||
| } | ||
|
|
||
| public override string DirectiveName => ParserConstants.CsharpViewModuleDirective; |
There was a problem hiding this comment.
You might want to rename CsharpViewModuleDirective to DotnetViewModuleDirective
| call: viewModuleManager.callViewModuleCommand, | ||
| registerMany: viewModuleManager.registerViewModules | ||
| }, | ||
| get virtualDirectory() { return getVirtualDirectory() }, |
There was a problem hiding this comment.
I can't find where this is needed.
This PR enables the user to reference a C# project compiled as a web assembly and invoke methods on imported "modules".
There are several things that need to be done: