Xamarin.Forms & Microsoft Unity 4.0.1
http://unity.codeplex.com/

Xamarin.Forms & Microsoft Unity 4.0.1

Xamarin.Forms has built-in features for dependency injection but there are gaps. When it comes to the traditional containers for services and view models, you will find many projects will use Autofac, Ninject or some other libraries. With the version of 4.0.1 in 2015, which addressed complaints of containers exceptions, I have preferred Microsoft’s Unity framework for several reasons. Unity allows me to lazy load, as needed, objects into the container as the application is running. I can also determine the lifespan of the object loaded. Autofac used to have lazy loading but that feature has been deprecated and now all objects must be defined prior to building the container. One more feature is a must and that is the ability to query the container objects like any other collection.

I wrapped the features I liked in Unity into an Injection Manager class in my project and provided generic methods to access services and view models as needed.  The wrapper now provides a way for me to load resources only as I need them and provides a communication framework without delegates and events which can cause memory issues. Examples of the this code and its use in a project can be found on my github site.

To view or add a comment, sign in

More articles by Les Brown

  • Accessibility in Xamarin.Forms

    In the last American census, it was estimated that 18.7% of the population has some type of disability and of those…

  • Docker Developer

    An Overview When talking about software containers it is helpful to start with its conceptual cousin known as…

    1 Comment
  • Speedup your development with Adobe XD

    If you have been developing mobile applications for any length of time, you have experienced the headache of creating…

    1 Comment
  • Globalization Alternatives in Xamarin.Forms

    Like all applications that are utilized across disparate cultures and languages, mobile has to be designed with…

  • Xamarin.Forms Behaviors and Commands UI Validation.

    No matter how much we try to ensure data integrity with business rules at various levels of the application, the UX…

  • Xamarin.Forms’ DependencyService as a full-fledged IOC.

    In a previously published article I touted the benefits of using Microsoft’s Unity library for dependency injection and…

    3 Comments
  • Xamarin.Forms Using Configuration Files

    One things I have really appreciated as part of .Net projects is the configuration file which has allowed me to…

    1 Comment
  • Xamarin - Custom Fonts

    Sometimes we just want our applications to have something different than what is given to us out of the box. This quick…

Explore content categories