Why web developers need to migrate to .NET Core and build web and webservice/API with ASP.NET Core MVC

2018 .NET Developer Survey Report: What is the state of .NET Core? Here we see that there are still a lot of .NET developers who are still watching. This article gives you a suggestion. This is just my personal opinion, I have good reasons to recommend .net programmers to use .net core instead of .net framework . Some people may disagree with me, but it's good to share ideas and discuss it. .net programmers or their teams always have various reasons to say that their system is still using the old system, which is obviously a business developer thing. So, I'm going to list a few things about who should migrate to using .net core instead of .net framework. Here are my thoughts:

  1. If you're the maintainer of a legacy Windows service, web application, or web service, you'll need to keep using the .NET Framework.
  2. If your application will be deployed on an older Windows server, such as Windows 2003/XP, you will need to continue to use the .NET Framework.
  3. If you're confident that your system won't be deployed to the cloud anytime soon, you can go ahead and use the .NET Framework now.
  4. If you don't have any choice to use the .net framework, such as a request from a company, you need to continue to use the .net framework. This situation is not good for your development. I advise you to learn .net core. company.
Beginners, just learn .NET Core!

If you are a beginner starting to learn ASP.NET or ASP.NET MVC, you may not know what .net framework and .net ore are. Don't worry! I suggest you take a look at the official documentation https://docs.microsoft.com/en-us/aspnet/index , you can easily see the comparisons and differences. Below are some parts of .net framework and .net core that I can share, you can follow each link to get the tools developed.

  .NET Framework .NET Core
Technology First Release 2002 (Mature) First Release 2016 (Mature)
Latest Version 4.7.2 (Reference Source) 2.0.6 (Open Source Software)
SDK Version 2.1.3
SDK Windows Only (Version 7, 8, 10) Windows (Version 7, 8, 10),
Linux (redhat, Ubuntu >14.04, Fedora, Debian, CentOS 7, openSUSE 24, Oracle Linux 7, SLES 12),
Mac
ASP.NET Performance 57,843 Request/Seconds (Plain Text) 1,822,366 Request/Seconds (Plain Text)
Here is some real world news as reference: ASP.NET Core – 2300% More Requests Served Per Second.
Best IDE/Editor Visual Studio 2017 Community (latest, FREE) Visual Studio 2017 Community (latest, FREE),
Visual Studio Code for Windows, Linux and Mac (FREE),
Visual Studio for Mac Community (FREE)
Web Framework Web Form, ASP, MVC (Web and Web API) MVC Core (Web, Razor Page, Web API)
Entity Framework (ORM) Entity Framework 6.2 (latest)
(Microsoft SQL Server, Oracle, MySQL (Official), PostgreSL, SQLite, IBM Data Server (DB2))
Entity Framework Core 2.0.1 (latest)
(InMemory (for Testing), Microsoft SQL Server, SQLite, PostgreSQL (Npgsql), IBM Data Server (DB2), MySQL (Official), MySQL (Pomelo), Microsoft SQL Server Compact Edition, Devart (MySQL, Oracle, PostgreSQL, SQLite, DB2, and more),
Oracle (not yet available), MyCat, Firebird-Community)
Frontend Plain MVC, Angular (mostly using MVC) Plain MVC, Angular, React, and Redux

 

Get started with .NET Core in just 5 minutes

If you are reading this article on a mobile laptop, please download and install the .NET Core SDK for your current operating system (Windows, Linux, Mac) . You don't need to install Visual Studio 2017 to develop .NET Core apps using the command line. After you have finished installing the SDK, open a Shell or PowerShell (in Windows), Terminal (in Linux or Mac), and enter the following command:

dotnet new console -o myApp
cd myApp
dotnet run

Congratulations, you've created your first console application using .NET Core. Now you can deploy this application by publishing it to any platform you want. On a Mac,

dotnet publish --runtime osx-x64

or android,

dotnet publish --runtime Android

Below is the complete list of runtime identifier catalogs . So, what does this command actually do:

dotnet new console -o myApp

When we run this command, it actually creates a console application project in the folder myApp . If you look in the folder myApp you should see the following files

myApp.csproj
Program.cs

The file itself is just a simple Hello world.Program.cs

using System;
 
namespace myApp
{
     class Program
     {
         static void Main(string[] args)
         {
             Console.WriteLine("Hello World!");
         }
     }
}

If you execute this command,

dotnet new --list

It will list the available templates from the box. This is what you might see,

If you replace console with mvc, it will create a web application project using ASP.NET core MVC .

Migrating to ASP.NET Core means migrating to modern web applications

Can I move to ASP.NET Core? The simple answer is of course  no, you can't just open an old ASP.NET Web Form or mvc 5 with Visual Studio 2017 and complete the transition to ASP.NET Core mvc. You can refer to the following old code migration strategies:

  1. If your web application uses web forms , you cannot directly convert or migrate it to ASP.NET Core. Because Web forms and MVC have completely different architectural models. MVC uses the separation of model, view and controller. There are also no webform control components (like web forms). ASP.NETCore MVC uses pure HTML5 elements. Of course you can use TagHelpers to create custom HTML attributes which will be converted to normal HTML5.
  2. If your web application is using ASP.NET MVC 5, you can first create a new ASP.NET Core MVC project and copy and paste some code into ASP.NET Core. This will require some tweaking, especially in RazorPage.
  3. If your web application is just a web api, you can start by creating a new ASP.NET Core Web API project instead of simply copying some code. A few tweaks are needed here because the ASP.NET Core web api is using web api 2.
  4. Use HTML5! HTML5 is only used for modern web application standards. Use HTML5 from the W3C (World Wide Web Consortium ) standard . Not just standards from Microsoft Edge , Chrome , Firefox , etc. Because each browser has its own features, called platform standards, and some browser platform features do not become W3C standards. If you only use the chrome feature standard, the web may only be bound by chrome and cannot be opened on other browsers. Not all browsers support other browser features.
  5. Responsive layout, responsive layout, responsive layout! Important things to say three times. We often hear developers say, " No, we don't need a responsive layout, it's just a desktop browser, we just make it static ". If your website is to c, you must do responsive layout, because now in the mobile age, more users will use their mobile browsers on ios/android to view.
  6. Don't use CSS directly in development projects. Use SASS or LESS .. You can easily do this with ASP.NET Core. You can even add Gulp, Grunt or webpack to compile CSS.

If your code is properly developed following the SOLID Principle , I believe that migration should be easy and not too much tweaking. However, if your code is spaghetti and needs to be refactored, .NET Core uses dependency injection by default. This is a common ASP.NET best practice, and of course it's better to do it now, not not do it at all. The benefits are also many, you can learn something new and your new web application will have better performance, be more modern and maintainable.

Say it to your boss: Migrate to .NET Core

I know what your boss will answer, yes, that scary phrase " is it compatible? "

My suggestion is to say: " Yes, it's compatible! They're all .NET. But we need some tweaking, some small coding changes to conform to programming best practices "

The ethos we need to move to .NET Core is, if not now, then when? With the release of .NET Core 2.1 right now, everything has changed. Technology has changed ( modern web apps , mobile, augmented reality, etc.), infrastructure has changed ( cloud, AI ), development architecture has changed ( containers, serverless ), etc.

Our industry does not respect tradition, only innovation. --- Microsoft CEO Satya Nadella

not so easy

The answer is yes. However, that doesn't mean impossible. It takes courage and knowledge. May the .NET power be with you!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325615367&siteId=291194637