Xamarin Forms and iOC
In the context of a Xamarin.Forms app that uses MVVM, a dependency injection container will typically be used for registering and resolving view models, and for registering services and injecting them into view models.
There are several advantages to using a dependency injection container:
A container removes the need for a class to locate its dependencies and manage their lifetimes.
A container allows mapping of implemented dependencies without affecting the class.
A container facilitates testability by allowing dependencies to be mocked.
A container increases maintainability by allowing new classes to be easily added to the app.
Some of the popular ones for Xamarin Forms are
That’s why we need some type of dependency injection tool for bootstrapping any service or viewmodel dependencies.
Before we were using Prism, now we are using Autofac. I talked to one of the developers of Prism this weekend (Dan Siegel ) he is also a
Xamarin MVP and he said that Prism is by far the fastest dependency injection container. It beat out all the others for registering dependencies at startup. Autofac is not the worst but its in the middle of the pack. Also Prism has a feature called modularization which allows you to load dependencies for each page as needed. Also the other dependency containers are immutable. Once loaded they cannot be changed. Prism is not. That is what makes it the number one dependency injection tool.