Introduction to NET Florin Olariu Alexandru Ioan Cuza

  • Slides: 51
Download presentation
Introduction to. NET Florin Olariu “Alexandru Ioan Cuza”, University of Iași Department of Computer

Introduction to. NET Florin Olariu “Alexandru Ioan Cuza”, University of Iași Department of Computer Science

ASP. NET Core MVC

ASP. NET Core MVC

Agenda Io. C/DI mechanism(part II) Models, views and controllers – an MVC refresher Controllers

Agenda Io. C/DI mechanism(part II) Models, views and controllers – an MVC refresher Controllers Models Views Web configuration with project. json Understanding MVC Implementing controllers Implementing views Implementing models and viewmodels

Using Dependency Injection with ASP. NET(1/12) Io. C/DI mechanisms

Using Dependency Injection with ASP. NET(1/12) Io. C/DI mechanisms

Using Dependency Injection with ASP. NET(2/12) Io. C/DI mechanisms

Using Dependency Injection with ASP. NET(2/12) Io. C/DI mechanisms

Using Dependency Injection with ASP. NET(3/12) Io. C/DI mechanisms

Using Dependency Injection with ASP. NET(3/12) Io. C/DI mechanisms

Using Dependency Injection with ASP. NET(4/12) Io. C/DI mechanisms PROS CONS Helps with adhering

Using Dependency Injection with ASP. NET(4/12) Io. C/DI mechanisms PROS CONS Helps with adhering to the Dependency Inversion Principle (DIP) DI introduces a learning curve for some developers Allows objects to be easily swapped with replacements DI may require a significant overhaul of existing projects Facilitates the use of the Strategy Design Pattern (SDP) Project timelines may not allow DI Improves the testability of applications Enables loose coupling of software components

Using Dependency Injection with ASP. NET(5/12) Io. C/DI mechanisms

Using Dependency Injection with ASP. NET(5/12) Io. C/DI mechanisms

Using Dependency Injection with ASP. NET(6/12) Io. C/DI mechanisms Transient

Using Dependency Injection with ASP. NET(6/12) Io. C/DI mechanisms Transient

Using Dependency Injection with ASP. NET(7/12) Io. C/DI mechanisms Transient Scoped

Using Dependency Injection with ASP. NET(7/12) Io. C/DI mechanisms Transient Scoped

Using Dependency Injection with ASP. NET(8/12) Io. C/DI mechanisms Transient Scoped Singleton

Using Dependency Injection with ASP. NET(8/12) Io. C/DI mechanisms Transient Scoped Singleton

Using Dependency Injection with ASP. NET(9/12) Io. C/DI mechanisms Transient Scoped Singleton Instance (special

Using Dependency Injection with ASP. NET(9/12) Io. C/DI mechanisms Transient Scoped Singleton Instance (special case of Singleton)

Using Dependency Injection with ASP. NET(10/12) Io. C/DI mechanisms Transient Scoped Singleton Instance (special

Using Dependency Injection with ASP. NET(10/12) Io. C/DI mechanisms Transient Scoped Singleton Instance (special case of Singleton)

Using Dependency Injection with ASP. NET(11/12) Io. C/DI mechanisms Transient Scoped Singleton Instance (special

Using Dependency Injection with ASP. NET(11/12) Io. C/DI mechanisms Transient Scoped Singleton Instance (special case of Singleton) Constructor injection

Using Dependency Injection with ASP. NET(11/12) Io. C/DI mechanisms Transient Scoped Singleton Instance (special

Using Dependency Injection with ASP. NET(11/12) Io. C/DI mechanisms Transient Scoped Singleton Instance (special case of Singleton) Constructor injection Action injection

Using Dependency Injection with ASP. NET(12/12) DEMO Using controllers and views Using Io. C

Using Dependency Injection with ASP. NET(12/12) DEMO Using controllers and views Using Io. C and DI Verifying routes Creating midlleware

Models, views and controllers – an MVC refresher(1/13)

Models, views and controllers – an MVC refresher(1/13)

Models, views and controllers – an MVC refresher(2/13)

Models, views and controllers – an MVC refresher(2/13)

Models, views and controllers – an MVC refresher(3/) Controllers

Models, views and controllers – an MVC refresher(3/) Controllers

Models, views and controllers – an MVC refresher(4/13) Controllers Is a subclass of the

Models, views and controllers – an MVC refresher(4/13) Controllers Is a subclass of the base class Controller

Models, views and controllers – an MVC refresher(5/13) Controllers Is a subclass of the

Models, views and controllers – an MVC refresher(5/13) Controllers Is a subclass of the base class Controller Lives into the following namsespace: Microsoft. Asp. Net. Core. Mvc

Models, views and controllers – an MVC refresher(6/13) Controllers Is a subclass of the

Models, views and controllers – an MVC refresher(6/13) Controllers Is a subclass of the base class Controller Lives into the following namsespace: Microsoft. Asp. Net. Core. Mvc Typically a controller returns an IAction. Result from its action methods

Models, views and controllers – an MVC refresher(7/13) Models

Models, views and controllers – an MVC refresher(7/13) Models

Models, views and controllers – an MVC refresher(8/13) Models Typically a model is DTO

Models, views and controllers – an MVC refresher(8/13) Models Typically a model is DTO class (properties)

Models, views and controllers – an MVC refresher(9/13) Models Typically a model is DTO

Models, views and controllers – an MVC refresher(9/13) Models Typically a model is DTO class (properties) For a cleaner architecture, you can use a view-specific model (or View. Model) to bind to a view.

Models, views and controllers – an MVC refresher(10/13) Views

Models, views and controllers – an MVC refresher(10/13) Views

Models, views and controllers – an MVC refresher(11/13) Views are stored in. cshtml files

Models, views and controllers – an MVC refresher(11/13) Views are stored in. cshtml files

Models, views and controllers – an MVC refresher(12/13) Views are stored in. cshtml files

Models, views and controllers – an MVC refresher(12/13) Views are stored in. cshtml files View. Bag allows you to store your own properties and display them in the view.

Models, views and controllers – an MVC refresher(13/13) Views are stored in. cshtml files

Models, views and controllers – an MVC refresher(13/13) Views are stored in. cshtml files View. Bag allows you to store your own properties and display them in the view. We can use tag helpers in your views for smoother syntax.

Web configuration with project. json(1/3)

Web configuration with project. json(1/3)

Web configuration with project. json(2/3) user. Secrets. Id: A GUID-like value used for working

Web configuration with project. json(2/3) user. Secrets. Id: A GUID-like value used for working with user secrets dependencies: A list of server-side dependencies version: The project version frameworks: . NET Core framework name and version build/runtime/publish options: Build/runtime configuration and a list of files/ folders to include when publishing the web app scripts: A list of scripts for actions that can be triggered by specific events, such as prepublish, postpublish, and others

Web configuration with project. json(3/3)

Web configuration with project. json(3/3)

Understanding MVC(1/4)

Understanding MVC(1/4)

Understanding MVC(2/4) Implementing controllers Http. Get: Uses the HTTP GET method with optional querystring

Understanding MVC(2/4) Implementing controllers Http. Get: Uses the HTTP GET method with optional querystring parameters Http. Post: Uses the HTTP POST method form submissions to create an entity

Understanding MVC(3/4) Implementing controllers Http. Get: Uses the HTTP GET method with optional querystring

Understanding MVC(3/4) Implementing controllers Http. Get: Uses the HTTP GET method with optional querystring parameters Http. Post: Uses the HTTP POST method form submissions to create an entity Http. Put: Uses the HTTP PUT method to edit an existing entity Http. Delete: Uses the HTTP DELETE method to delete an existing entity Http. Patch: Allows partial model updates instead of a full PUT request Accept. Verbs: Allows multiple action verbs to be specified

Understanding MVC(4/4) Implementing controllers DEMO

Understanding MVC(4/4) Implementing controllers DEMO

Understanding MVC(1/4) Implementing views

Understanding MVC(1/4) Implementing views

Understanding MVC(2/4) Implementing views View. Data, View. Bag, and Temp. Data

Understanding MVC(2/4) Implementing views View. Data, View. Bag, and Temp. Data

Understanding MVC(3/4) Implementing views View. Data, View. Bag, and Temp. Data View. Data[" Patient.

Understanding MVC(3/4) Implementing views View. Data, View. Bag, and Temp. Data View. Data[" Patient. Id"] = id; View. Bag. Patient. Data = "some. Data"; Temp. Data[" User. Token"] = user. Token. Data; @{ View. Data["Title"] = "Patient Details"; } <h 2> Patient Details </h 2> <ul> <li> ID: @View. Data[" Patient. Id"] </li> <li> Name: @View. Data[" Patient. Name"] </li> </ul>

Understanding MVC(4/4) Implementing views View. Data, View. Bag, and Temp. Data @{ View. Data["

Understanding MVC(4/4) Implementing views View. Data, View. Bag, and Temp. Data @{ View. Data[" Title"] = "Patient Index"; } <h 2> Patient Index, with Tag Helpers </h 2> <ul> @for (int i=0; i<10; i++) { <li> <a asp-controller =" Patient" asp-action ="Details" asp-route-id ="@i" asp-route-name ="Patient @i" > Patient # @i </a></li> } </ul>

Understanding MVC(1/6) Implementing models and View. Models

Understanding MVC(1/6) Implementing models and View. Models

Understanding MVC(2/6) Implementing models and View. Models A model is just a class file

Understanding MVC(2/6) Implementing models and View. Models A model is just a class file with a. cs file extension.

Understanding MVC(3/6) Implementing models and View. Models A model is just a class file

Understanding MVC(3/6) Implementing models and View. Models A model is just a class file with a. cs file extension.

Understanding MVC(4/6) Implementing models and View. Models A model is just a class file

Understanding MVC(4/6) Implementing models and View. Models A model is just a class file with a. cs file extension.

Understanding MVC(5/6) Implementing models and View. Models A model is just a class file

Understanding MVC(5/6) Implementing models and View. Models A model is just a class file with a. cs file extension.

Understanding MVC(6/6) Implementing models and View. Models DEMO

Understanding MVC(6/6) Implementing models and View. Models DEMO

One more thing…(1/2)

One more thing…(1/2)

One more thing…(2/2) “In summary, ASP. NET MVC gives developers the choice of shooting

One more thing…(2/2) “In summary, ASP. NET MVC gives developers the choice of shooting themselves in the foot, although it's certainly possible to do it cleanly. As such, it is suited for developers who are comfortable with web development and have a clean style, but it is not for the developers who want Widgetized behavior a la winforms without having to delve too deeply into the markup. ”

Bibliography https: //docs. asp. net/en/latest/tutorials/first-web-api. html - By Mike Wasson and Rick Anderson Nagel,

Bibliography https: //docs. asp. net/en/latest/tutorials/first-web-api. html - By Mike Wasson and Rick Anderson Nagel, Christian. Professional C# 6 and. NET Core 1. 0 Chowdhuri, Shahed. ASP. NET Core Essentials

Questions Do you have any other questions?

Questions Do you have any other questions?

Thanks! See you next time!

Thanks! See you next time!