Convention over Configuration in MvvmCross
MvvmCross, a cross-platform MVVM framework, utilizes the concept of "Convention over Configuration" to simplify the development process by reducing the need for explicit configuration. This approach allows developers to focus on unconventional aspects of their application, leveraging default conventions to handle typical scenarios.
Basic Principles
In MvvmCross, Convention over Configuration is primarily applied in how Views and ViewModels are linked. By default, MvvmCross uses a naming convention to associate Views with their corresponding ViewModels. For example, if you have a `TipView`, MvvmCross will automatically look for a `TipViewModel` to pair with it. This convention eliminates the need for explicit configuration, making it easier to manage the relationship between Views and ViewModels[11].
Implementation
1. ViewModel Naming Convention: MvvmCross follows a specific naming convention where a ViewModel is typically named by appending "Model" to the name of the View. For instance, `FirstView` is linked to `FirstViewModel` by default[5][11].
2. Automatic Linking: When using this convention, MvvmCross automatically locates and links the appropriate ViewModel to its View. This is particularly useful when you don't use generic parameters to explicitly define these relationships[11].
3. Flexibility: While MvvmCross relies on conventions for simplicity, it also provides flexibility. Developers can override these conventions when necessary by using generic parameters or custom configurations. This allows for more control over how Views and ViewModels are associated, especially in complex applications[11].
Benefits
- Reduced Configuration: By leveraging conventions, developers spend less time writing configuration code, focusing instead on application logic.
- Improved Readability: The codebase becomes more readable as the repetitive configuration tasks are minimized.
- Simplified Maintenance: With fewer explicit configurations, maintaining and updating applications becomes easier.
Customization
While MvvmCross relies heavily on conventions, it also supports customization. Developers can override default behaviors by implementing custom logic in key classes like `App` and `Setup`. For example, you can customize the IoC container or change how ViewModels are constructed and initialized[9].
In summary, MvvmCross's implementation of Convention over Configuration streamlines the development process by automating typical tasks, allowing developers to concentrate on unique aspects of their applications. This approach enhances productivity and simplifies application maintenance while still providing the flexibility needed for complex scenarios.
Citations:[1] https://en.wikipedia.org/wiki/Convention_over_configuration
[2] https://visualstudiomagazine.com/articles/2018/05/08/build-a-xamarin.forms-application.aspx
[3] https://leaware.com/creating-cross-platform-xamarin-applications-using-the-mvvmcross-framework/
[4] https://learn.microsoft.com/en-us/archive/msdn-magazine/2009/february/patterns-in-practice-convention-over-configuration
[5] https://www.codeproject.com/Articles/863695/Introduction-to-Mvvmcross-Platform
[6] https://github.com/MvvmCross/MvvmCross-Samples
[7] https://www.mvvmcross.com/documentation/fundamentals/viewmodel-lifecycle
[8] https://books.sonatype.com/mvnref-book/reference/installation-sect-conventionConfiguration.html
[9] https://www.mvvmcross.com/documentation/advanced/customizing-using-App-and-Setup
[10] https://www.mvvmcross.com/documentation/getting-started/getting-started
[11] https://www.mvvmcross.com/documentation/tutorials/tipcalc/a-note-about-views-and-viewmodels
[12] https://www.mvvmcross.com/documentation/getting-started/mvvmcross-overview