Unity dependency injection for UWP - unity-container

I'm creating a UWP program using the PRISM 6 library from GitHub which has support for using Unity for dependency injection. However the current release of Unity (including the latest code in GitHub) has no mention of UWP support.
Does anyone know if the current Unity release is compatible with UWP projects?

The current Unity release (4.0.1) is compatible and working on UWP.
Edit: Due to project restructuring, samples have moved to a separate repository. One of the samples that is using Unity is the SplitView sample. Simply derive your app from PrismUnityApplication.

Related

Xamarin Android app out of the box shows undefined Android.Support, Android.Views, Android.Content in MainActivity

I needed to rebuild my fairly ancient Xamarin Forms app from scratch and in the process arrived at a situation where I had a new working iOS app but had needed to delete the draft Android app and start it again. So as a next step I added a vanilla Android app project out of the box and immediately what I saw was that (in MainActivity) Android.Support, Android.Views and Android.Content were undefined with wiggy red lines beneath -- for example in a reference to Android.Support.V7.Widget.Toolbar.
Trying to solve the problem, I set each of Target Framework, Minimum Android Version and Target Android Version to Android 9.0 Pie (API Level 28). In SDK Manager I checked that Android SDK Location and Java SDK Location were 'Found' and that Android SDK Platform 28 was installed.
The following NuGets came installed along with the project, I deleted them and reinstalled them (removing bin/obj folders in between): Xamarin.Android.Support.Core.Utils, Xamarin.Android.Support.CustomTabs and Xamarin.Android.Support.Design.
I tried installing NuGets Xamarin.Android.Support.v7.*. And I added the Xamarin.Forms NuGet. I tried adding 'use' declarations.
None of this helped.
For comparison I separately installed a blank Android app solution-- it worked perfectly out of the box.
Android is pretty new to me - would be grateful for suggestions on fixing this.
The app has a .NET Standard 2.0 project, an iOS project, the (vanilla) Android project (all three with Xamarin Forms), and a .NET Standard 2.0 library project.
I'm using Visual Studio for Mac V8.5.4 (stable) on MacOS 10.15.3.
I noticed that the content of MainActivity.cs is quite different, depending whether the Android project is created separately or as part of a Xamarin Forms solution. Also the provided NuGets are different. So perhaps what I was trying to do, adding an Android app to an existing XF solution, is simply not allowed.
To fix the problem, I created an empty Xamarin Forms solution with Android and iOS projects, added a further empty library project, then in Finder replaced the content of all the project folders, except the Android one, with the content of the corresponding folders in my working solution (the one with a working iOS app).
Migrating to AndroidX is a good idea though.
I don't know if this will help, but you should migrate to AndroidX as soon as possible, nevertheless. Xamarin has migrated to them, starting from Forms 4.5
Here is some more information about the libraries - Introducing AndroidX for Xamarin
There is a special NuGet package for the migration - Xamarin.AndroidX.Migration. Also available is a built-in functionality in Visual Studio - here
What I can suggest is you try to migrate to AndroidX libraries, since the old support libraries won't be supported from now on, and you will surely encounter some issues if not like this one, then something else will pop-up in the future.

Unity for MVC5 in NuGet

I want to use Unity for MVC 5. I found this Link:- http://www.c-sharpcorner.com/UploadFile/dacca2/implement-ioc-using-unity-in-mvc-5/
I don't find Unity Bootstrapper for MVC5 in NuGet. What would be its equivalent ?
I think what I am looking for is Unity Application Block for MVC5.
I need these following libraries which would be compatible with MVC5:-
Microsoft.Practices.Unity
Microsoft.Practices.Unity.Configuration
Microsoft.Practices.Unity.MVC
Microsoft.Practies.Unity.RegistrationByConvention
Which Package from NuGet should I download ??
The ownership changed after version 4.01. There have been namespace changes and possibly some API changes but it works with MVC 5.
The packages you need are
Unity
Unity.Mvc
and possibly Unity.WebApi
Most of documentation and articles on the web is for version 4. If this is your first time working with a DI container you may want to use the 4.01 version so you can follow along with those online resources.

Managing nuget packages for .net standard xamarin forms project

I am converting xamarin forms pcl to .net standard. In the project I use skia sharp and azure mobileservices.
My understanding was that if I reference these libraries in the .net standard class library and then add a reference to this .net standard class library in my android/ios/uwp projects all would be fine.
However it seems that I need to add the nuget packages for skiasharp and azure mobileservices to each project (android/ios/uwp). Is this indeed the case? if so, how is this better than using PCL?
I got the android project working, but I needed to add all the nuget packages to the android project.
I got the uwp project working without any nuget packages, which confuses me even further.
Using PCL and .NET Standard are basically the same - both are just API contracts or a subset of the full .NET Framework. But there is a MAJOR advantage to .NET Standard: .NET Standard has far more APIs - especially if you are using 1.3+ (netstandard1.3 has the System.IO APIs which aren't available in PCL).
With regards to NuGets, you typically still need to reference the NuGet package in all the app projects because some platforms have different implementations to take advantage of platform features. Think of .NET Standard as a subset of all the platform APIs - this is why SkiaSharp works just fine for some platforms. However, Android and iOS have a different implementation to take advantage of platform features.
Although you aren't doing Android development directly (since you are using Xamarin.Forms) you wouldn't have noticed something. If you JUST include the .NET Standard package, you get the basic SkiaSharp that can, for example, convert between a Xamarin.Forms color and a SkiaSharp color. However as a result of including the package in the android app, you can additionally convert from an Android color to a SkiaSharp color.
Personally, I always include all the NuGets into the app projects just to be safe.
Here are some docs that may help you:
https://learn.microsoft.com/en-us/dotnet/standard/net-standard

.net standard library with HttpCient for xamarin forms

I was trying to create a common library for using HttpClient to consume an API. I was planning to make it in .net standard so as to share it with my xamarin.forms project right now and any future ones. However the highest version of .net standard I managed to use was 1.0. HttpClient needs standard2.0. I have included the latest version of .netstandard nuget into my xamarin.forms.
I have noticed that xamarin.forms runs in net4.5. According to the documentations the max I can go with this is standard1.1. Is there any work around around these to a .net standard common project or is my only option to make a .net framework project/xamarin portable library?
I used to be in the same situation and I managed to pull through this. First I tried to upgrade my current PCL project to .netStandard, but it was always failing, so I decided to create a new Project A Class Library (.NETStandard), moved all my files to the new project and re-install all nuget packages.
New project configuration:
Target Framwork: .NET Standard 2.0
Output type: Class Library
Make sure you're using Microsoft Visual Studio > version 15.3
Hope it helps.
I did manage to get HttpClient working in .net standard after manually importing the class. It needed an additional reference which is why it threw an error when I downgraded from .netcore.
This seems to work sometimes and throws reference errors other times. These errors go when I close and re-open visual studios.

I am developing iOS and Android app with Xamarin Forms in MAC. I am installing PCL Xamarin.Mobile, but i am getting error

The error i am getting while installing PCL. Any idea about below mentioned error?
Could not install package 'xamstore-xamarin.mobile 0.7.1'. You are
trying to install this package into a project that targets
'.NETPortable,Version=v4.5,Profile=Profile259', but the package does
not contain any assembly references or content files that are
compatible with that framework. For more information, contact the
package author.
From Xamarin Developer Matt Ward on the Xamarin Forums
The NuGet package xamstore-xamarin.mobile 0.7.1 only supports MonoAndroid and MonoTouch. It contains MSBuild property files for these two frameworks. You will not be able to install it into a Portable Class Library (PCL) project since it does not have any files that target any PCL framework.
Instead you should be able to add it to a Android or iOS project.
Similarly Xamarin.Mobile from the component store supports Android and iOS projects. It has assemblies for those platforms as well as for Windows Phone 7/8 and Windows 8 (WinRT). So you would be able to add that component into an Android or iOS project but not a PCL project.

Resources