Uno Platform Using Dependency Injection - c#

I am trying to inject dependencies into a constructor of a ViewModel in a project using the Mvvm framework. I am using the Uno Platform. I tried Mvvm frameworks Prism and Mvvmcross but they remain incomplete and I couldn't get them to build. I am now trying Mvvmhelpers which builds fine but I don't think that caters for a IOC container.Could someone recommned a way forward?

Uno Platform can use any .NET Standard library, so you could potentially just install Autofac or Unity and plug it into your custom MVVM framework.
MvvmLight binding is provided via Uno.MvvmLight, which is also available as a NuGet package in preview. Although it hasn't been updated for a while, I will put up a Issue on GitHub to get it up to date again with the upstream.
For my personal favorite MvvmCross - there is a work in progress PR on GitHub, which will bring Uno support directly into MvvmCross. But before that happens, you can follow the instructions from Nick Randolph on his blog to get the preview version up and running.
The platform is still quite new so it takes time for things to settle and third party libraries to adopt it, but after the release of WinUI 3.0 it should stabilize and the support should grow faster.
Update
I totally forgot to mention ReactiveUI which has first-party support for Uno Platform already.

Related

MvvmCross file plugin still required?

Regarding the file plugin (OS independent file system access) for MvvmCross:
Do I understand correctly that this plugin was created at a time when file system access wasn't yet possible using .NET standard?
Meaning for new projects there's no reason to use the file plugin and I can use .NET standard without any drawbacks?
The MvvmCross.Plugins.File plugin was created back when we had Portable class libraries and didn't have any profile that had any System.File.IO namespaces available to us.
So with the introduction with .NET Standard, most of what it does has become obsolete. So you are right to say that for new projects, you could get away without having to use this plugin at all, because all of the API is available to you in .NET Standard.
Do I understand correctly that this plugin was created at a time when file system access wasn't yet possible using .NET standard?
No, MvvmCross is a cross-platform MVVM framework.
Among the features MvvmCross provides are:
ViewModel to View bindings using own customizable binding engine,
which allows you to create own binding definitions for own custom
views
ViewModel to ViewModel navigation, helps you share behavior on
how and when to navigate
Inversion of Control through Dependency
Injection and Property Injection
Plugin framework, which lets you
plug-in cool stuff like GPS Location, Localization, Sensors, Binding
Extensions and a huge selection of 3rd party community plug-ins
For more details, you could refer to the link. https://github.com/MvvmCross/MvvmCross-Samples
Meaning for new projects there's no reason to use the file plugin and I can use .NET standard without any drawbacks?
Plugins have advantages for framework, but implementing direct in the UI projects is perfectly acceptable too.

Xamarin ReactiveUI - You are referencing the Portable version of ReactiveUI in an App error

I've used a portable template to create a Xamarin app, and I have installed reactive UI into both the portable library and the Android library. However, when I deploy the app to my phone and cause a RaisePropertyChanged to be fired. I get the error:
You are referencing the Portable version of ReactiveUI in an App.
Reference the platform-specific version.
I think I must be misunderstanding the level of compatibility with Xamarin. Do I need to create a shared project to use ReactiveUI?
re: howdy
Don't think we have met, come join us in Slack https://reactiveui.net/slack !
re: problem
Check your references. It looks like ReactiveUI was not installed correctly into your Android application. The framework uses the Bait & Switch pattern - this error will happen is the switch is missing. You need to install reactiveui nuget package into your PCL/standard library AND platform application.
re: do you need to use shared?
Nope; PCL/netstandard works fine and thats my recommendation.

Is there any way to share code between UWP apps and WPF apps?

To be clear, I follow the MVVM pattern, and I want to structure my project such that I can share my model code between a UWP app and a standard WPF app. The code I want to share has no UI. I don't relish the thought of finding new tools to replace the ones that I've been using for years that take care of certain tasks like logging, connecting to a document oriented database, etc.
I attempted to start writing a UWP wrapper around some code I already have and reference the model project directly. Visual Studio refused to let that happen, showing me an error message that says "Unable to add a reference to project 'ACK.Model'". The same thing happened when I attempted to put the model in a Universal Library and reference it from a WPF app. I'm not trying to share WPF code. Just the model layer that has no reference to UI libraries.
This is a scary proposition, because it means that if I want to do anything substantial I have to choose to either jump 100% to UWP or stay 100% WPF. NewtonSoft.JSON might have a universal distribution (ASP.NET MVC), but what about ElasticSearch.NET, and other tools needed to make important apps?
I found where the "Portable Class Library" project type was hiding. PCLs will allow me to share my code across WPF and Universal apps as that was one of the options. This solves the simple case of the Model part of my code, but I (still) can't use some of the libraries I want. There are still a large number of libraries that I need that do not have PCL available.
About a year later, with the advent of Visual Studio 2017 there is a more complete solution. If you target your libraries to .Net Standard then the library is compatible with both .Net Core apps and the monolithic .Net targeted app. The support for standard .Net libraries and APIs is fairly complete, as is the support for modern C# language features.
The general advice now is this:
Target .Net Standard for all libraries
Target the appropriate platform for your actual application. (UWP or WPF).
NOTE: if your library has to interact with C libraries or applications, you have to take extra care to make sure you load the correct version.
It appears that there is a solution, but it has to be adopted by the whole tool chain you want to use. When Microsoft introduced Windows Store apps in Windows 8, they also introduced a Portable Class Library (PCL). The purpose of the PCL is to share code between different parts of your application.
When you create a PCL in Visual Studio 2015, you can specify the types of APIs you want it to be accessible from:
Universal Apps
Mono
.Net Core 5
.Net 4.6
This of course, limits the APIs available to you but most of the ones you want to use are OK as long as it's not UI related. There are other limitations as well:
Your project can only be edited in Visual Studio 2015 or greater
You don't have access to special directories from the Environment variable (i.e. user Documents directory, etc.)
You can't link to a library designed for only one of your target platforms (i.e. libgit2sharp, etc.)
There's no way to browse the API for this subset--MSDN needs to get on the stick. MSDN has updated much of the API documentation, but it's still difficult to figure out what applies to your PCL
However, you can link any library designed for a single target platform to your PCL. It's not ideal, but it's better than nothing.
The ASP.NET MVC stack has been ported to using PCLs, so you can use NewtonSoft.JSON directly as well as any other of those libraries used by that application. However, there are several libraries that have not been ported.
This arrangement forces you to think about how you want to integrate better. The .Net Core 5 seems to be stable, but support is in it's infancy. The current generation of Universal Apps as of VS 2015 update 1 uses .Net Core 5 directly.
There are several features from Nuget that are not currently supported even though work is under way:
MS Build extensions (major changes to MSBuild and the project.json structure)
Install/uninstall scripts (related to the removal of the concept of install)
Content (related to install/uninstall, but work is in progress on this)
Content transforms (related to lack of install/uninstall)
I wish I had a more complete answer. But this is as far as I got once I discovered the PCL and how it evolved for the current infrastructure.
I'm in the process of creating a game creation toolkit that incorporates version control right off the bat. I want to be able to deploy a game as a Windows 10 app, or as a standard WPF app, but due to the libraries I'm using to integrate version control I need to create the editor as a standard WPF app. I had to be a bit creative in building the shared code and importing the correct libraries.
First, my project hierarchy:
Project.Model (Portable Class Library)
Project.Model.Versioning (standard C# library)
Mvvm.Toolkit (Portable Class Library)
Editor (Standard WPF application)
I want the core PCL to be able to load a project and deserialize the JSON encoded objects. The PCL did have access to System.IO, but surprisingly it is not the same as the one defined in the standard C# library. Here's how I had to fix things:
After adding the package reference to NewtonSoft.JSON, I had to change the target framework in the packages.config file:
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="portable-net452+win81" />
All projects dependent on my Project.Model class had to install the `system.io.filesystem' package from nuget so that the System.IO.FileInfo etc. objects were the same.
While this is definitely not a panacea, it's also not a dead end. I'm sure there are more gotchas, but this will at least help with some of the problems.
a .NET Standard library could be used to share a Model-View-ViewModel architecture between a WPF project and a UWP project.
https://www.syncfusion.com/ebooks/xamarin-forms-succinctly/sharing-code-among-platforms
https://devblogs.microsoft.com/dotnet/announcing-uwp-support-for-net-standard-2-0/

Use MvvmCross with dot42

I'm currently trying some techniques for writing Android programs with C#. I found MvvmCross that is really nice for an old WPF programmer. Sadly, the free Xamarin version does not allow the use of MvvmCross, and licences are far too expensive for playing around.
Now i stumbles across dot42, but could not manage to load MvvmCross into a dot42 project via nuget. I get
Could not install package 'MvvmCross.PortableSupport 3.1.1'. You are trying to install this package into a project that targets 'Dot42,Version=v2.3.3', but the package does not contain any assembly references or content files that are compatible with that framework.
so I guess, Dot42 isn't supported by MvvmCross. Is it possible to use MvvmCross with dot42?
You won't currently be able to easily use nuget with dot42 - nuget hasn't yet added any extension for them.
Also, you won't be able to use MonoDroid-targetted assemblies for dot42 - those assemblies are built against Xamarin's runtime - not dot42.
However... if anyone wanted to get MvvmCross working against dot42, then I believe this should be possible - as dot42 supports quiet a good .Net functionality set, including PCLs. To do so would require editing the source code, cloning the MonoDroid projects and then changing the code that targets Xamarin/MonoDroid runtime objects to instead target the dot42 equivalents. I'd personally love to see this done, but haven't had time to work on it myself.

Reactive Extensions installation package doesn't contain ReactiveUI libraries

I want to try ReactiveUI however Rx installation package doesn't contain ReactiveUI. I guess that ReactiveUI is in some standalone installation package, but I was not able to find it. Can anybody share with information whether or not ReactiveUI is supported by Microsoft anymore? And if yes please give me a link to ReactiveUI library.
Thank you in advance!
UPD: I've found a sample application on http://www.reactiveui.net/. It contains ReactiveUI dlls, but I want to get official ReactiveUI build.
ReactiveUI is not a Microsoft project - the best way to get official binaries for ReactiveUI is via the NuGet package, which will also pull in the correct version of the Reactive Extensions.
If you go to the website you mention http://www.reactiveui.net/, there is a 'download' button at the bottom. This gives you both a sample application and the ReactiveUI libraries.
You can find the dlls you mention under ReactiveUI 2.2.0.0 Sample\ReactiveUI.Sample\ReactiveUI.Sample\bin\Debug\
Or, of course, grab the source from their github and compile them yourself.
P.S. I found all of that with no prior knowledge of this library. Maybe this was more of a quesion for Google, not this site?

Categories