How to define a class with different implementations for desktop and browser? #18332
Unanswered
TheRealQuantam
asked this question in
Q&A
Replies: 2 comments 10 replies
-
You're halfway there. Put an interface in the core assembly, with concrete implementations in the platform assemblies. On app start the platform assemblies register the concrete implementation with a services register, which the core can then request as needed. |
Beta Was this translation helpful? Give feedback.
10 replies
-
On top of other suggestions, you can use |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have an Avalonia 11 app that builds for both desktop and WebAssembly browser, meaning a core assembly with the MVVM, a desktop assembly, and a web assembly. How can I write a class with different implementations for desktop and web that can be used by the core assembly? I might hypothesize that I'd write an interface in the core assembly then different implementations of it in the desktop and web assemblies, but how then do I instantiate the appropriate class from the core assembly, especially given how aggressive trimming is in WebAssembly builds?
I can't use
#if
to select for the target because the core assembly only has one target, yes? And I can't really switch between the two implementations at runtime (OperatingSystem.IsBrowser()
) because they involve different dependencies.Beta Was this translation helpful? Give feedback.
All reactions