TinyMvvm for .NET MAUI – Preview

TinyMvvm is an open-source project I started back in 2017 primary to be used in my own apps, both private projects, and client projects. I recently released 3.0 that has been in preview for a long time and I used it in apps I have shipped to the app stores. After the 3.0 release, I have focused on bringing TinyMvvm to .NET MAUI and now there is a public preview available.

Instead of migrating the TinyMvvm.Forms project to .NET MAUI I created a new .NET 6 project with the name TinyMvvm.Maui. That means that both will live side-by-side The first thing I did there was to copy all the code from the Forms project and migrate it to MAUI, .NET 6, and C#10. That means that I am using the MAUI namespaces instead of the Xamarin.Forms namespaced, I am using global usings and file-scoped namespaces.

The big change compared to the Forms version of TinyMvvm is how you initialized it. The only thing you need to do now is to use the extension method UseTinyMvvm() on the MauiAppBuilder and initialize the resolver as shown below. If your ViewModels or View are in another assembly you can specify it as an argument to UseTinyMvvm(Assembly viewAssembly, Assembly, viewModelAssembly). If you don't use Shell navigation you can pass an argument to use classic navigation. UseTinyMvvm(bool useClassicNavigation).

The next step is to analyze how I can optimize TinyMvvm for .NET MAUI.

public static MauiApp CreateMauiApp()
{
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                })
                .UseTinyMvvm();

            var app = builder.Build();

            Resolver.SetResolver(new ServiceProviderResolver(app.Services));

            return app;
}

You can install the package from NuGet.

To find out more about how to use TinyMvvm you can read the documentation for Xamarin.Forms. Before the stable release of this package, the documentation will be fully updated with how to use it with .NET MAUI.

If you have feedback please create an issue on GitHub.

One thought on “TinyMvvm for .NET MAUI – Preview

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.