Architecting Modern Web Application With New Features Of ASP.NET Core 2.1

Before a decade, businesses didn’t have multiple options to develop customized enterprise applications with unique features and the latest programming languages. To provide the optimum user experience, they had to spend much time and it incurred a high cost. But today digitization has given 360-degree revolution to the software industry! When it comes to customize enterprise web application development, there are multiple technologies to choose from and one of the prominent one is ASP .NET development. It is the perfect amalgamation of web development models which contains all the required services to build the robust enterprise web applications.

Most of the web developers use ASP.NET MVC to build web applications, but the latest ASP.NET core 2.1 frameworks provide far more benefits compared to the other. ASP.NET Core is an open source, a cross-platform framework developed by both Microsoft and its community and combines MVC structure and Web API into a single framework.

ASP.NET Core 2.1 is the latest update to Microsoft’s open source and cross-platform web framework for .NET and is now available for everyone. ASP.NET Core 2.1 includes the support of real-time web applications with SignalR and has a variety of new features and improvements which helps to make web development with .NET fast, reliable and secure.

Let’s dive deep to know how new features of ASP.NET Core 2.1 can help the enterprise .NET development.

New features of ASP.NET Core 2.1

HTTPClientFactory to handle HTTPClient instances

As per the community of ASP.NET, it is “an opinionated factory for creating HTTPClient instances”. If you are a developer and have worked with the HTTPClient in the production software, you may have encountered many challenges and headaches. In the service-oriented architecture, if several connections are needed to be established, the only way it can be done is by using several HTTP instances. So, when you create HTTPclient within your code, two problems arise;

  • Each one has its own connection pool for the remote server which means you need to pay the cost of reconnecting the remote server for every client you create
  • If the socket crosses the threshold limit, it can run into socket exhaustion. When HttpClient is disposed of, the open connection remains for up to 240 seconds in TIME_WAIT state.

With HttpClientFactory, you can create and register Httpclient instances and can simply add the HttpClient as a service and then use it via the IHttpClientFactory interface in your controllers. Being a simple approach, the enterprise can use it to create larger applications. Moreover, developers can even encapsulate the HTTPClient in own types and expose for consumption only methods that simply return a result for clients, without knowing the implementation details.

SignalR for real-time web functionality

In ASP.NET Core 2.1, SignalR is an open-source library that can help to add real-time web functionality to apps hassle-free. It allows bi-directional communication between server and client. SignalR supports Web Socket and other compatible techniques for older browsers. It includes APIs for creating a server to client remote procedure calls (RPC), connection management (for instance, connect and disconnect events), grouping connections, and authorization. SignalR is built-in by default which means basic chat application can be developed within minutes.
Some features of SignalR for ASP.NET Core:

  • Handles connection management automatically
  • Sends messages to all connected clients simultaneously. For example, a chat room
  • Sends messages to specific clients or groups of clients
  • Scales to handle increasing traffic

Razor UI class library to create reusable UI

One of the new features of ASP.NET core 2.1 is Razor UI class library which helps in improving UI in reusable class libraries. With Razor UI, it makes easier to develop and include Razor based UI in a library and share it across multiple projects. Previously, to build Razor assets, it should be deployed and requested.

But, with ASP.NET Core 2.1, Razor compilation is integrated into build process which results in faster app start times. Moreover, ASP.NET core shares common assets such as identity features like login, register, forgot password but resulted in code replication across individual projects, leading to increased technical debt. A new Razor SDK will enable building Razor files into a class library projects that can be packed into a NuGet package. Reusable UI components can be created with Razor UI similar to Angular. With this Razor UI class library, ASP.Net core development can be taken to a whole different level. By integrating Razor compilation into the build:

  • The app startup time is significantly faster.
  • Provides fast updates to Razor views and pages at runtime are still available as part of an iterative development workflow.

Identity UI library and scaffolding

In the previous version, to get the support of identity functionality, developers had to generally make the decision to add support for it when creating an app project. If in-case developers want to add support later, the process would be to create a brand-new web app project with the appropriate support and then copy the files from the new app into your existing app. This consumed more time and was not an ideal solution.

The good news is that starting with ASP.Net Core 2.1 you can scaffold Identity into existing ASP.Net Core projects. To achieve this we can simply right-click on the project, then “Add” and “New scaffolded item”. The benefit of this approach is fewer boilerplate files in your new projects, but with no loss in functionality or your ability to customize behavior scaffolder and just select the ASP.Net Core Identity components that you want to add to the application.

HTTPS for security

HTTPS is enabled by default in ASP.NET core 2.1 and has features that ease to set up HTTPS in production. Developers may have noticed that on console output, other than listening on http://locatlhost:5000, the running app is also listening on https://localhost:5001. In some backend service where HTTPS is being handled externally, HTTPS at each node is not needed. When you install the ASP.Net Core 2.1 SDK, a certificate is installed and you get prompted if you want to add it to the trusted certificate root on your development machine. This is how HTTPS will then work when you debug locally.

GDPR Compliance and Privacy

Protecting the privacy of users is always the major concern for any website when it comes to data handling. ASP.NET Core 2.1 makes it easy to comply with the latest privacy requirements including the EU General Data Protection Regulation (GDPR). Additionally, to enable HTTPS by default, ASP.NET Core apps are prepared with infrastructure for managing cookie consent and deleting and exporting user data. With GDPR, users have the right to examine the data, edit the data and delete the data entirely from your application.

Rich Swagger Support for customizing UI

With rich swagger support; developers can refrain from writing different attributes to write the swagger documentation of an API. ASP.NET core 2.1 has added an opinionated layer that infers the possible responses based on what you have done with your actions. It provides options for documenting the object model and customizing the UI that match your theme. Some of the highlights include:-

  • XML comments
  • API information and the description
  • Data annotations
  • Response types
  • Customized UI and many more

Functional Testing support

Functional testing has become easier in ASP.NET core 2.1 with WebApplicationFactory. It will invoke the entire application, host it in memory and enables the developers to create a custom factory that configures to “HttpClient” without “touching the wire”. When WebApplicationFactory is initialized, it will invoke the app from end-to-end to check the entire results.

Microsoft has created a new package, Microsoft.AspNetCore.Mvc.Testing which takes care of some pitfalls when trying to test MVC applications using TestServer.

  • Copies the .deps file from your project into the test assembly bin folder
  • Sets the content root in the application’s project so that static files and views can be found
  • Provides a class WebApplicationTestFixture<TStartup> that streamlines bootstrapping of your app on TestServer.

Concluding note

In an ever-evolving software development industry, there is a constant enhancement of languages, frameworks, tools, and methodologies. Today most of the businesses are looking for the quick development ways to launch the application; ASP.NET core 2.1 loaded with the features such as portability, performance, simple deployment, modularity, cloud support, open source and better support help the enterprises to make the most out of their web development endeavors.

So, are you the one who is looking to develop your next enterprise software in ASP.NET core? Let’s talk!

Author: SPEC INDIA

SPEC INDIA, as your single stop IT partner has been successfully implementing a bouquet of diverse solutions and services all over the globe, proving its mettle as a boutique ISO 9001:2015 certified IT solutions organization. With efficient project management practices, international standards to comply, flexible engagement models and superior infrastructure, SPEC INDIA is a customer’s delight. Our skilled technical resources are apt at putting thoughts in a perspective by offering value-added reads for all.


Guest Contribution

We are looking for industry experts to contribute to our blog section through fresh and innovative content.

Write For Us

Our Portfolio

Proven Solutions Across Industries
Technology for Real-Life

Visit Our Portfolio

Scroll Up