Where do design patterns appear in .Net 6 Mvc 5 project ?

Arshad Nazeer 21 Reputation points
2022-03-17T18:58:17.987+00:00

Hi.

In all the design patterns, I see that, there is an object of some class being created (if its a ConsoleApplication then the object is created in the Main() method). My question is: why in .Net Mvc Core 5 project these design patterns need to exist, and also where it need to exist (the Mvc App has no Main() method...).

What is the scenario where I would need design patterns in Mvc 5 project?

Thanks.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,190 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Brando Zhang-MSFT 2,956 Reputation points Microsoft Vendor
    2022-03-18T05:53:03.893+00:00

    Hi @Arshad Nazeer ,

    The MVC is a framework which is built on asp.net core, it use a lot of design patterns by default, like MVC Pattern, or else. Design patterns are used to reuse code, make code easier for others to understand, and ensure code reliability

    0 comments No comments

  2. Bruce (SqlWork.com) 56,846 Reputation points
    2022-03-20T00:14:25.223+00:00

    design patterns are names for common algorithms. .net core uses several common design patterns, builder, dependency injection, which in turn is dependent on interface design, the model / view / controller pattern, etc.

    none of this has anything to with main(). c# followed the practice of c in using a global module name main() as the standard entry point for a program. so the minimum hello world in c# was:

    using System;
    
    public class Program
    {
        public static void Main()
        {
            Console.WriteLine("Hello World");
        }
    }
    

    following practices of other modern languages, c# 10 (released with .net 6), the main is optional. so now a hello world program is:

    Console.WriteLine("Hello World");
    

    making use of this feature, net 6 uses a minimal api. instead of the template creating a program file, and startup file, there is just the program file. as with previous version of .net core, the builder pattern is used for configuration, and defining services (DI) and the process loop.

    0 comments No comments