Need advice migrating ASP.NET Core MVC to .NET MAUI

Bryan Cass 46 Reputation points
2022-06-02T20:54:26.107+00:00

I built a commercial web site with ASP.NET Core MVC that is hosted on an AWS EC2 server that uses a SQL Server database also hosted on AWS RDS. It's running fine for the past couple years as a web app only. We would like to expand to mobile to expose limited features from the web app (NOT port the whole app over to mobile). The screens/pages will be different from the web app and workflow will also be different, but still pushing/pulling data to and from the SQL Server db.

Does it make sense to try to merge the MVC code/app into new Visual Studio solution with an added MAUI project, and create a shared Components project for shared resources? Or would it be simpler/quicker to just create some APIs for database access and develop a completely independent mobile app with .NET MAUI? I can envision hours and hours or work trying to merge the MVC business logic and models and views into a .NET MAUI Hybrid solution, but if there is a tutorial or someone has already done it successfully, I'd be willing to give it a try.

Dan Roth did a great demo of migrating a Blazor app to .NET MAUI, but I think MVC would be more difficult.
ASP.NET Community Standup - Let's build an app with .NET MAUI and Blazor

Thanks!

Developer technologies ASP.NET ASP.NET Core
Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Takahito Iwasa 4,851 Reputation points MVP Volunteer Moderator
    2022-06-02T21:56:10.68+00:00

    Hi, @BryanCass-6939

    ASP.NET Core is the M-V-C architecture, and .NET MAUI is typically the M-V-VM architecture.
    I think you need to at least remake the UI. (V-C-> V-VM)
    However, the model is generally optimally designed and generally reusable if it is loosely coupled according to the MVC architecture.

    First, in order to make M (Model) common, it is recommended to separate the ASP.NET-dependent part from the backend, as in the microservices approach.

    The following AWS tools can help you analyze and split your ASP.NET Core application.

    https://docs.aws.amazon.com/microservice-extractor/latest/userguide/what-is-microservice-extractor.html

    Then you have a backend API and ASP.NET Core and .NET MAUI access the same API.

    .NET MAUI builds the UI with the MVVM approach instead of the WebController's MVC approach.

    https://learn.microsoft.com/en-us/dotnet/maui/xaml/fundamentals/mvvm

    Let's talk about source code management.
    You can divide it into the following three.

    • Common API project to manage Model
    • Project for the web
    • Project for mobile (.NET MAUI)
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-06-06T15:38:47.843+00:00

    your current MVC site should expose a webapi callable from the new mobile app.

    you should add a new library project where you can share common code between the MVC app and the mobile app. validation, some common business logic, etc.

    depending on your skills, you can use MAUI's xml to create the mobile UI or use MAUI's support of blazor to create the UI in html/CSS and razor. This is done by MAUI hosting a webview (browser) and blazor engine.


  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-06-06T18:25:13.217+00:00

    You should spend some time deciding on the mobile app strategy. and will you support both iPhone and android? will you have an android and an iPhone team? do you need native look, or will you have a common custom look?

    these decisions can help. if you are decided on Xamarin you three choices

    1) Xamarin calling the native UI. For IOS you use Storyboard to design the UI and call Cocoa UI (SwiftUI is not supported at this time). For android you use the Android Designer.

    2) Xamarin using MAUI UI (or the old Xamarin forms, but I'd use MAUI at this point) . The UI is design using the xml Xaml files. While a common component library, the MAUI components use native UI, so you get a native look.

    3) Xamarin use Blazor (hosted by MAUI). You write the UI in html/css using Blazor components.

    Mobile app development is its own world. Testing is very difficult (lots of devices and OS versions), and at least 2 app stores. You will find you need a dedicated team.

    my team (very small) has tries several approaches:

    1) Hybrid app - native mobile app hosting webview and javascript.(similar to the blazor approach, only writing in.javascript(
    2) Native React - Common code base written javascript. Under the covers same as Blazor, a native app hosting a web view and javascript
    3) Native app - Swift for IOS and Kotlin for Android. Though even our native apps use webview javascript for common code.

    As our mobile apps tend to be just UI's to the server, we have found the native app the simplest. There is just not that much common code at the UI layer. Swift or Kotlin is not different from C#. And you can use the native designers.

    if we get a new mobile app, we will look at Xamarin. But the shared code benefit would need to out weigh the learning curve of MAUI Xmal. Blazor is the same as the Hybrid, and we already know javascript.

    Also we use Mac's for mobile development because the mobile toolchains work best there, and Mac is required for any real IOS development.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.