-
Notifications
You must be signed in to change notification settings - Fork 1
Architecture
This document serve to explain some stuff
The IoC container used in this project is AutoFac, selected due to ease of use, as well as good documentation and multiple examples of people using it on their Xamarin project.
To use an IoC container:
- Register types
- Specify lifetime
- Resolve
The ViewModelLocator is to allow design time evaluation of the ViewModel while still allowing constructor injection of the ViewModel.
XAML:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="NottCS.Views.MenuPage"
BindingContext="{Binding Source={StaticResource Locator}, Path=Menu}"
Title="Menu">
ViewModelLocator class:
- Register the type with the container and specify the lifetime
builder.RegisterType<MenuViewModel>().InstancePerDependency();
- Expose the property to be binded
public MenuViewModel Menu => _container.Resolve<MenuViewModel>();
The constructor injection is done through the use of the IoC Container.
The logging is done through the use of NLog.
Main advantages:
- Can specify logging levels
- Easily include timestamp of log
- Easily format log string to include more information like callsite
- Easily change logging medium, i.e. Console, Text file, etc.
NLog setup found under App.xaml.cs under SetupNLog() function. (Updated as of 3 Nov 2018)
Sample usage:
private readonly ILogger<MainViewModel> _logger;
public MainViewModel(ILogger<MainViewModel> logger)
{
_logger = logger;
logger.LogInformation("MainViewModel created");
}
Since this application has been updated to use a drawer style, there are 2 ways for navigation to happen. Page terminologies illustrated here
1. Replace the Detail page. This is needed when an item on the Drawer/Menu Page is selected.
Usage:
await _navigationService.SetDetailPageAsync(viewModelType, navigationParam);
2. Navigate from the current Detail page. This is needed when the Detail page itself needs to navigate further.
Usage:
await _navigationService.NavigateToAsync<ViewModelType>(navigationParam);
A DTO is basically a Data Transfer Object. Not to be confused with Model. These are basically dedicated for data transfer with the backend only, not to be used in anything else. Can refer to this,