Developing Enterprise Apps using Xamarin.Forms
After many years working with developers of enterprise apps, we know that they face several challenges, including:
- App requirements that can change over time
- New business opportunities and challenges
- Ongoing feedback during development that can significantly affect the scope and requirements of the app
With these in mind, it’s important to build apps that are both flexible and that can be easily modified or extended over time. Designing for such flexibility can be difficult, as it requires an architecture that allows individual parts of the app to be independently developed and tested in isolation without affecting the rest of the app.
The traditional approach to designing and building an app results in what is referred to as a monolithic app, where components are tightly coupled with no clear separation between them. Typically, this monolithic approach leads to apps that are difficult and inefficient to maintain, because it can be difficult to resolve bugs without breaking other components in the app, and it can also be difficult to add new features or replace existing features.
An effective remedy for these challenges is to partition an app into discrete, loosely coupled components that can easily be integrated together into an app. Such an approach offers the following benefits:
- It allows individual functionality to be developed, tested, extended, and maintained by different individuals or teams.
- It promotes reuse and a clean separation of concerns between the app’s horizontal capabilities, such as authentication and data access, and vertical capabilities, such as app specific business functionality. This allows the dependencies and interactions between app components to be more easily managed.
- It helps maintain a separation of roles by allowing different individuals or teams to focus on a specific task or piece of functionality according to their expertise. In particular, it provides a cleaner separation between the user interface and the app’s business logic.
However, there are many issues that must be resolved when partitioning an app. These include:
- Deciding how to provide a clean separation of concerns between the user interface controls and their logic.
- Deciding whether to use a dependency injection container.
- Choosing how components that are inconvenient to link by object and type references can communicate.
- Deciding how to navigate between pages, including how to invoke navigation and where navigation logic should reside.
- Deciding how to validate user input for correctness. The decision must include how to validate user input and how to notify the user about validation errors.
- Deciding how to perform authentication and how to protect resources with authorization.
- Deciding how to access remote data from web services, including how to reliably retrieve data and how to cache data.
- Deciding how to unit test the app.
Introducing Enterprise Application Patterns using Xamarin.Forms
Today we’re excited to introduce you to a preview version of an eBook that offers guidance on these issues (and more).
The eBook focuses on core patterns and architectural guidance for developing Xamarin.Forms enterprise apps that are easier to test, maintain, and evolve. Guidance is provided on how to implement the Model-View-ViewModel (MVVM) pattern, dependency injection, navigation, validation, and configuration management, while maintaining loose coupling. In addition, there’s also guidance on performing authentication and authorization with IdentityServer, accessing remote data from containerized microservices, and unit testing.
The eBook comes with source code for the eShopOnContainers application, which is an online store that includes the following functionality:
- Authenticating and authorizing with a backend service.
- Browsing a catalog of shirts, coffee mugs, and other marketing items.
- Filtering the catalog.
- Ordering items from the catalog.
- Viewing the user’s order history.
- Configuring settings.
The following diagram shows a high-level overview of the architecture of the sample application:
The sample application ships with three client apps:
- An MVC application developed with ASP.NET Core.
- A Single Page Application (SPA) developed with Angular 2 and Typescript.
- A cross-platform mobile app developed with Xamarin.Forms.
The sample application also includes the following backend services:
- An identity microservice, which uses ASP.NET Core Identity and IdentityServer.
- A catalog microservice, which is a data-driven, create, read, update, delete (CRUD) service that consumes an SQL Server database using EntityFramework Core.
- An ordering microservice, which is a domain-driven service that uses domain driven design patterns.
- A basket microservice, which is a data-driven CRUD service that uses Redis Cache.
These backend services are implemented as microservices using ASP.NET Web API, and are deployed as unique containers within a single Docker host. Client apps then communicate with the backend services through a Representational State Transfer (REST) web interface.
The eBook focuses on building cross-platform enterprise apps using Xamarin.Forms and uses the eShopOnContainers mobile app as an example. The following diagram shows the pages from the eShopOnContainers mobile app that provide the functionality outlined earlier:
The mobile app consumes the backend services provided by the containerized microservices. However, it can also be configured to consume data from mock services for those who wish to avoid deploying the backend services.
Enterprise Application Patterns using Xamarin.Forms focuses on core patterns and architectural guidance for developing Xamarin.Forms enterprise apps that are easier to test, maintain, and evolve. Guidance is provided on how to implement MVVM, dependency injection, navigation, validation, and configuration management while maintaining loose coupling. In addition, there’s also guidance on performing authentication and authorization with IdentityServer, accessing remote data from containerized microservices, and unit testing.
The eBook also ships with a sample application, which can be downloaded here.
The eBook is complementary to Architecting and Developing Containerized and Microservice based .NET Applications, which focuses on developing containerized microservices and their deployment.
Other guides worth reading include Architecting and Developing Modern Web Applications with ASP.NET Core and Azure, Containerized Docker Application Lifecycle with Microsoft Platform and Tools, and Microsoft Platform and Tools for Mobile App Development.