-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling .NET WebAssembly code from views #1526
base: main
Are you sure you want to change the base?
Conversation
…tvvm into feature/csharp-client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to rename CsharpViewModuleDirective to DotnetViewModuleDirective
@@ -107,6 +107,7 @@ const dotvvmExports = { | |||
call: viewModuleManager.callViewModuleCommand, | |||
registerMany: viewModuleManager.registerViewModules | |||
}, | |||
get virtualDirectory() { return getVirtualDirectory() }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: