Tips for converting existing ASP.NET applications to ASP.NET Core

karthikchintala

Karthik Chintala

Posted on November 7, 2022

Tips for converting existing ASP.NET applications to ASP.NET Core

The evolution of microservices greatly impacted how we think, write and manage applications in the cloud environment.

The existing monoliths are being migrated slowly to implement microservices and their patterns.

Scalability is one of the major aspects that developers/architects looking for migrating from ASP.NET Framework to ASP.NET Core.

I was reading the ASP.NET Core in Action, 3rd Edition, and found this chapter interesting on migrating existing asp.net applications to asp.net core. So, this blog post is about migrating.

Gist

In this post, we’ll see

  • Drawbacks of monolith applications
  • Challenges involved in converting ASP.NET Web Forms, MVC, and WCF to ASP.NET core applications
  • When to convert an application to ASP.NET Core

Drawbacks of a monolith application

  1. Less scalable : Instead of scaling only the UI/API horizontally you may have to scale it vertically as it’s a monolith application
  2. The codebase may become huge overtime
  3. Deployment problems : Having to deploy a feature to larger codebases takes more time than deploying a small codebase.
  4. Difficult to test : Adding a small feature to the project may affect the whole system. A full regression is required.
  5. Tied to one technology : The choice of technology is limited to ASP.NET. If a problem can be solved easily with other technologies, with the asp.net framework or any monolith application you cannot do it

But, there are benefits of asp.net core that come along with migrating existing asp.net applications such as

  • Cross-platform deployment
  • Modularity
  • Performance

However, converting the existing asp.net applications may involve additional cost and technical expertise to do that transition.

There are difficulties converting the following applications to asp.net core

  1. ASP.NET Web Forms
  2. Is built using WCF
  3. Is huge and uses advanced MVC features

Let’s see why it is difficult to transition the above use cases

Transitioning from ASP.NET Web Forms to ASP.NET Core

If the application is asp.net web forms, trying to convert it is not advisable as web forms are tied to System.Web.dll and IIS.

The conversion involves a complete rewrite of the app in ASP.NET Core.

It doesn’t mean your hopes of converting are dead at this point. There is a community-driven repository that guides on how to reuse much of the markup as in blazor.

Blazor server provides a component-based application that is similar to the web forms application model. So, you can convert web forms application gradually to asp.net core blazor application.

You can slowly transition the APIs into asp.net core web API application by reducing the reliance on the web forms concepts like ViewData.

asp.net core in action by andrew lock
ASP.NET Core In Action, Third edition

Transitioning from the WCF application

Windows Communication Foundation (WCF) is partially supported in ASP.NET Core. Again, it’s possible to build using the libraries for both the WCF client side (part of the .NET foundation) and the server-side (supported by the .Net foundation).

However, the above-mentioned libraries don’t support all of the APIs available in the .NET framework WCF. If you need all of them for sure, don’t migrate to ASP.NET Core for now.

Transitioning from MVC

If an MVC application is complex and uses the extensive features of MVC like message handlers, then porting to ASP.NET Core will be more difficult.

Although ASP.NET Core is built with similar features as MVC, the underlying architecture is different as ASP.NET Core is written from scratch.

aspnet core in action

ASP.NET Core in Action (save 45% now)

Andrew Lock teaches you how you can use your C# and .NET skills to build amazing cross-platform web applications.

Read Now

When to port an application to ASP.NET Core

If the existing application will need significant future development , then migrating to ASP.NET Core is a good choice.

If your application is rarely used and may not involve additional development efforts, then it’s better not to migrate to an ASP.NET Core application.

Microsoft will support .NET Framework for years to come (you may have to update the framework) though we have a new release of ASP.NET Core 7.

The best approach to migrating an ASP.NET core project is to start small and integrate with an existing application or start your new project as ASP.NET Core and integrate with an existing monolith.

It’s best to work in chunks rather than converting the entire application at once and Microsoft also provides YARP (a reverse proxy for .NET) and also ASP.NET Migration Tooling in Visual Studio to help implement the strangler fig pattern.


Pic Credits: Microsoft Learning

In the early migration, we see only a small portion of the modern application created in early migration and gradually most of the legacy system is migrated to the modern and then once the migration is complete we should have everything in the modern system.

Conclusion

ASP.NET Core applications offer modularity and performance at the same time. And they are best suited for microservices in the .NET ecosystem.

If your existing business is built on ASP.NET Framework and is working well and getting fruits for you then you don’t need to migrate to ASP.NET core.

Converting existing applications to asp.net core is possible but it involves planning, time, effort, and resources.

But, understanding the hard parts of the existing application is critical to transforming to an ASP.NET Core application. It helps to think about what it takes to convert the hard parts of the application first.

If you are creating a new product and the product really doesn’t need to be scalable for a huge number of users, you may not need to do it in ASP.NET Core. But, I’d recommend creating applications in ASP.NET Core now because .NET Framework may eventually retire sometime in the future and you may have to look up for ASP.NET Core again.

This article is sourced from a chapter in ASP.NET Core In Action, 3rd Edition written by Andrew Lock.

ASP.NET Core in Action (45% off)

This Andrew Lock’s revised bestseller reveals the latest .NET patterns, including minimal APIs and minimal hosting..

Read Now

Andrew lock also gives a great insight into how the ASP.NET Core works and how it processes a request and many great things we can do with ASP.NET Core. It’s worth a read.

References

  1. ASP.NET Core In Action
  2. BlazorWebFormsComponents – Github
  3. WCF Client Side
  4. WCF server side
  5. Microsoft .NET Framework Lifecycle
  6. Strangler Fig Pattern

The post Tips for converting existing ASP.NET applications to ASP.NET Core appeared first on Code Rethinked.

💖 💪 🙅 🚩
karthikchintala
Karthik Chintala

Posted on November 7, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related