DEV Community

Cover image for ASP.NET Core New BackEnd Framework! CodeBehind 2.5 Released
elanatframework
elanatframework

Posted on

ASP.NET Core New BackEnd Framework! CodeBehind 2.5 Released

CodeBehind is a new back-end framework based on ASP.NET Core. CodeBehind is owned by the Elanat team and competes with Microsoft's default web frameworks (Razor Pages, MVC, and Blazor) on .NET Core.

CodeBehind is simpler, more flexible, and much faster than Microsoft's default web frameworks. According to the latest tests of the Elanat team, CodeBehind is up to 40% faster than Microsoft's Razor and MVC pages.

The link below is an article on the stunning performance of the CodeBehind framework by the Elanat team.
Performance test, ASP.NET Core MVC and Razor Pages vs CodeBehind Framework in version 2.2

If you want to know more about modularity in CodeBehind framework, please read the article below.
Modularity in the default mode

CodeBehind Framework VS ASP.NET Core MVC

Every project based on CodeBehind automatically supports modularity; it is only necessary to distribute the DLLs in the bin folder and the View pages in the root of the currently active project.

CodeBehind 2.5

CodeBehind 2.5 on NuGet

In this version, several middleware classes have been added to make CodeBehind configuration much easier than before. From now on, you can configure the CodeBehind framework version 2.5 and later according to the following codes in ASP.NET Core:

CodeBehind 2.5 Configure in ASP.NET Core (Program.cs class)



var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

SetCodeBehind.CodeBehindCompiler.Initialization();

app.UseCodeBehind();

app.Run();


Enter fullscreen mode Exit fullscreen mode

The above configuration is based on the default MVC architecture in CodeBehind, where requests are first routed to the View, and then the controller and model are specified from the View. This is a revolutionary architecture presented by the Elanat team.

You can leave error handling to CodeBehind automatically by adding the boolean value true to the UseCodeBehind method.

Example:



app.UseCodeBehind(true);


Enter fullscreen mode Exit fullscreen mode

Note: Please note that you must specify the error page in the options file located in the code_behind directory.

You can also use the controller configuration in Route. The Elanat team has also transformed the structure of this type of configuration with its initiatives, and you don't need to do complex configurations.

The configuration of the controller in Route for the CodeBehind framework is done as follows:



var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

SetCodeBehind.CodeBehindCompiler.Initialization();

app.UseCodeBehindRoute();

app.Run();


Enter fullscreen mode Exit fullscreen mode

Adding the UseCodeBehindRoute method will section each section of the URL.

Note: Section means the strings between slash characters.
Example: example.com/section0/section1/section2

The UseCodeBehindRoute method sets the section value to 0; if there is a Controller with the same name as the value of the first section, the UseCodeBehindRoute method will execute the Controller.

Example:

CodeBehind Controller



using CodeBehind;

namespace YourProjectName
{
    public partial class home : CodeBehindController
    {
        public void PageLoad(HttpContext context)
        {
            Write("Route work fine");
        }
    }
}


Enter fullscreen mode Exit fullscreen mode

According to the Controller class above, if the path example.com/home is requested, the Controller class above is executed and the Route work fine string is returned.

If the name of the Controller class matches the section in the url, Regardless of the namespace, the Controller class is executed.

The Controller class name is case sensitive. Therefore, the path example.com/Home cannot execute the Controller with the class name home.

This process is modular, so if you have an external dll that contains the Controller class of the CodeBehind framework, you can copy it to wwwroot/bin to call the Controller class.

Unlike the weak default structure of MVC in ASP.NET Core, the process of executing the Controller is dynamic and there is no need to create methods with IActionResult output; as a result, instead of a hard connection and full dependency, you will have a loose connection and little dependency.

Example:

Dynamic Controller in CodeBehind



using CodeBehind;

namespace YourProjectName
{
    public partial class home : CodeBehindController
    {
        public void PageLoad(HttpContext context)
        {
            if (Section.Count() < 2)
            {
                Write("This is main page");
                return;
            }

            switch (Section.GetValue(1))
            {
                case "first": View("/page1.aspx"); break;
                case "second": View("/page2.aspx"); break;
                case "third": View("/page3.aspx"); break;
                case "fourth": View("/page4.aspx"); break;
            }
        }
    }
}


Enter fullscreen mode Exit fullscreen mode

The code above shows a Controller that returns the string This is main page if there is no other section after section main. If another section named first, second, third, and fourth is requested after the main section, the pages page1.aspx, page2.aspx, page3.aspx and page4.aspx will be returned respectively.

Example:

Requesting example.com/main/first returns the page page1.aspx.

You can leave error handling to CodeBehind automatically by adding the boolean value true to the UseCodeBehindRoute method.

Example:



app.UseCodeBehindRoute(true);


Enter fullscreen mode Exit fullscreen mode

Note: Please note that you must specify the error page in the options file located in the code_behind directory.

Which ASP.NET Core framework should we choose?

ASP.NET Core framework

Please write us the answer to the above question in the comments section.

Related links

CodeBehind on GitHub:
https://github.com/elanatframework/Code_behind

CodeBehind in NuGet:
https://www.nuget.org/packages/CodeBehind/

CodeBehind page:
https://elanat.net/page_content/code_behind

Top comments (0)