0% found this document useful (0 votes)
2 views

setting-up-an-mvc-application-slides

This document provides an overview of setting up an ASP.NET Core MVC application, including exploring the project structure and configuring the site. It highlights the importance of the Program and Startup classes, detailing how to register services and configure middleware. The summary concludes with a note that dependency injection is built-in and that the next step involves creating the first page using MVC.

Uploaded by

nshansundar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

setting-up-an-mvc-application-slides

This document provides an overview of setting up an ASP.NET Core MVC application, including exploring the project structure and configuring the site. It highlights the importance of the Program and Startup classes, detailing how to register services and configure middleware. The summary concludes with a note that dependency injection is built-in and that the next step involves creating the first page using MVC.

Uploaded by

nshansundar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Setting Up an MVC Application

Gill Cleeren
CTO XPIRIT BELGIUM

@gillcleeren www.snowball.be
Overview
Exploring the project structure
Configuring the site
Exploring the Project Structure
Creating a New Project
Available Project Templates
Project Structure (Empty)
Project Structure (Web Application MVC)
Demo
File à New Project
Exploring the new project
Site Configuration
Project Structure
Program.cs

public class Program


{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>


Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
Program.cs

public class Program


{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>


WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}

Program.cs in .NET Core 2.1


Program.cs

public class Program


{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>


WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
Startup.cs

public class Startup


{
public void ConfigureServices(IServiceCollection services)
{
...
}

public void Configure(IApplicationBuilder app,


IHostingEnvironment env)
{
...
}

}
public void ConfigureServices(IServiceCollection services)
{
//register services here through Dependency Injection

ConfigureServices Method
Tight Coupling

MyClass Logger
Adding Interfaces to the Mix

ILogger

MyClass Logger
Adding Interfaces to the Mix

DI
MyClass Logger
Container

ILogger
public void ConfigureServices(IServiceCollection services)
{
//register framework services
services.AddControllersWithViews();
//register our own services (more later)

ConfigureServices Method
Configure Method

public void Configure(IApplicationBuilder app,


IHostingEnvironment env)
{
//add middleware components here
}
Middleware Request Pipeline

Request

Middle Middle Middle


ware 1 ware 2 ware 3

Response
Configure Method

public void Configure(IApplicationBuilder app,


IHostingEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseStatusCodePages();
app.UseStaticFiles();
app.UseEndpoints(endpoints =>
{ ... });
}
Ordering Middleware Components

Request

Middle Middle Middle


ware 1 ware 2 ware 3

Response

Response Static End Point


Compression Files
The Startup of the Application

Application starting ConfigureServices method


Ready for requests
Program class Registering services

Configure method
Startup class
Pipeline is created
Demo

Configuring the site


Summary
ASP.NET Core MVC applications have a
new project structure
Dependency injection is built-in
Up next:
Creating the first page using MVC

You might also like