100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Enterprise Web Development C# Summary Samenvatting HoGent $5.90
Add to cart

Summary

Enterprise Web Development C# Summary Samenvatting HoGent

 28 views  0 purchase
  • Course
  • Institution

Summary for the course Enterprise Web Development C#, found in the third year of applied Computer Sciences Samenvatting van het vak Enterprise Web Development C#, in het 3de bachelor van het traject Toegepaste Informatica (TI)

Preview 10 out of 38  pages

  • December 23, 2023
  • 38
  • 2023/2024
  • Summary
avatar-seller
Enterprise Web Development C#

Tom De Bakker

23/12/2023




1

,Inhoudstafel
Enterprise Web Development C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Evaluatie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Chapter 1: Introduction To The .NET Ecosystem 5
.NET Explained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
.NET: The Ecosystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Deveopment flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Hello world . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Your first application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Class libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Creating a Class Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Linking a Class Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Referencing a Class Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
GIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Repository structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Chapter 3: Model & Unit Testing (Solving The Problem Domain) 8
Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Members of a class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Access modifiers for members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Access modifiers for classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Readonly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Destructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Associations & collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
IEnumerable<T> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
ICollection<T> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
IList<T> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Superclass definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Subclass definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Abstract class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Static members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Static class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Unit testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Test Driven Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
When to write tests? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Assert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Naming conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Show me the code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Creating a new test project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
BlackJack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Own notes from the lessons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
The global modifier with the using directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

Chapter 5: David’s & Goliath’s Architecture 21
Modern Wep Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21


2

, Traditional vs Modern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
What should you choose when . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Suport in ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Hosting Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Razor pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Model View Controller (MVC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Web API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Blazor Web Assembly (Blazor WASM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Blazor server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Common design principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Comman Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Chapter 6: Suit Up Wear A Blazor 23
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Hosting Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Client Side (WASM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Server Side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
SnakeEyes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Why a domain project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Unboxing the client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
dotnet new blazorwasm –hosted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
First run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Retrieve data on the Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Send data from the Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Fake it till you make it . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Different terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Async programming and the Task interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Bogus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Faking users and roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Infrastructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
FakeAuthenticationProvider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Dependency injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
_Imports.razor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
App.razor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Index.razor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
AuthorizeView component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Blazor Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Component events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

Chapter 7: Ain’t no REST for the wicked 34
What’s an API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
What is REST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Uniform interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Client-Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Stateless . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Cacheable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Layered System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Consumer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
HTTP methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
HTTP status ranges in a nutshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Document your API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
OpenAPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Swagger UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Building a REST API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Input validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
FluentValidation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38




3

,Enterprise Web Development C# INHOUDSTAFEL


Enterprise Web Development C#
• GitHub website cursus
∘ Shift + vraagteken voor hulp in slides
Evaluatie
• 100% exam in the examination period on your own device
• Open internet maar zonder AI tools, passive internet gebruiker
• Implement parts of a larger solution
• If the code does not compile a.ka. Build Errors = 0/20
∘ Catchup exam is done orally via Teams, only possible given a valid reason
• Je mag andere editors zoals Rider gebruiken, zolang het geen AI tools bevat




4

, CHAPTER 1: INTRODUCTION TO THE .NET ECOSYSTEM



Chapter 1: Introduction To The .NET Ecosystem
.NET Explained
.NET: The Ecosystem
• Languages
∘ C#
∘ F#
∘ Visual Basic
• Libraries
∘ Base Class Library
∘ 3rd party
∘ Provided by the NuGet package manager
• Compilers
∘ Roslyn
■ Compiles to Intermediate Language Code (=bytecode) to be run on the CLR (=JVM)

∘ RyuJIT
■ Compiles to native code

• Runtimes
∘ Common Language Runtime
■ An Application Virtual Machine

■ Compiles the Intermediate Language Code Just In Time to Machine Code




Deveopment flow
C# code gets compiled using Roslyn into Intermediate Language Code which is stored in Dynamic Link Libraries
(DLLs), which can then be executed using the Common Language Runtime (CLR). Finally the CLR compiles
the code Just In Time (JIT) to machine code




Figure 1: Development flow


History
• .NET Framework
• .NET Core
• .NET Standard




Figure 2: History of .NET


5

,Hello world CHAPTER 1: INTRODUCTION TO THE .NET ECOSYSTEM


Hello world
Your first application
• Information about the SDK dotnet --info
• Get a list of all possible starter templates dotnet new list
• Create a new console application dotnet new console -o NameApp -f net6.0 --use-program-main


The --use-program-main flag disables top-level statements

• Build the application dotnet build
• Build and run the application dotnet run

When running this command dotnet build is implicitly implied.


Class libraries
In C#, a class library is a collection of classes, interfaces, structs, enums, and other types of .NET code that
can be reused in multiple applications. It is essentially a container for reusable code that provides a way to
encapsulate and organize functionality that can be used across different C# projects or applications.
Class libraries are typically compiled into DLL (Dynamic Link Library) files, which can be referenced by other
C# projects or assemblies. They can’t be run by themselves.

Op het examen zijn er ook gedeelde class libraries die aan elkaar gelinked zullen zijn

Creating a Class Library
1. Create a new folder hello-class-libraries with a src folder inside.

mkdir hello -class - libraries
cd hello -class - libraries
mkdir src
cd src

2. Create a new Console Application

dotnet new console -o App -f net6 .0

3. Create a Class Library

dotnet new classlib -o Domain -f net6 .0


Linking a Class Library
We want to use Classes from the Domain project in the App project so:
1. Execute the following command in the src folder (the root folder) to link the Domain Class Library to
the Application.

dotnet add App/App. csproj reference Domain / Domain . csproj

2. Open the App.csproj file and see what’s added by the command.

<ItemGroup >
<ProjectReference Include ="..\ Domain \ Domain . csproj "/>
</ ItemGroup >

Without a explicit reference you cannot use any classes defined in the Domain.csproj class library from
the Console Application.


6

,GIT CHAPTER 1: INTRODUCTION TO THE .NET ECOSYSTEM


Referencing a Class Library

In plaats van using Domain; bij de imports, kunnen we ook namespace Domain ... rond onze klasse
zetten.

GIT
Repository structure
Standard folder structure:
• Projectname (repository)
• .gitignore (in the root folder)
• readme.md (information about the repository)
• src/
∘ project1/
■ Files for project1

∘ classlibrary1/
■ Files for classlibrary1

∘…
• tests
∘ Same as src/ but for tests




7

, CHAPTER 3: MODEL & UNIT TESTING (SOLVING THE PROBLEM DOMAIN)



Chapter 3: Model & Unit Testing (Solving The Problem Domai
Classes
Members of a class
• Fields (=attributes)
• Methods
• Constructor - destructor
• Properties

Access modifiers for members
• public
∘ Accessible from everywhere
• private
∘ Only accessible from within the class
private is the default

• internal
∘ Only accessible within the same assembly
■ An assembly = one unit of deployment, version control, …

• protected
∘ Only accessible within the class and all classes that inherit from this class
In Java: also accessible in same package, not in C#!

• protected internal
∘ Combination of protected and internal

Access modifiers for classes
Classes, structs or records directly declared in a namespace can be public or internal (default)

Directly declared in a namespace = not nested in another class or struct

Nested classes or structs in structs can be declared public , internal or private .
Nested classes or structs in classes can be declared all of the previous ones ( public , private , protected
, internal or protected internal ).
The default for nested classes or structs is private .

Derived classes andrecords can’t have greater accessibility than their base types

Fields
[modifier] datatype variableName
• Always private
• Can be static
∘ Linked to the class and not to an instance
∘ Static members only exist once per class
• Naming convention: _camelCase

public class BankAccount
{
private string _accountNumber ;
private decimal _balance ;
}




8

,Classes CHAPTER 3: MODEL & UNIT TESTING (SOLVING THE PROBLEM DOMAIN)


Constants
• Use the keyword const
• Must be initialized when declared
• Value can never change
• Implicit static, i.e. doesn’t have the keyword
• Naming convention: PascalCase

public class BankAccount
{
public const decimal WithdrawCost = 0.25M;
}

Accessed through the class name:

Console . WriteLine ( BankAccount . WithdrawCost );


Readonly
• Use the keyword readonly
• Can only be assigned a value once
∘ At declaration OR in the constructor
• Not required at declaration <> const

public class BankAccount
{
private readonly string _accountNumber ;
private decimal _balance ;
}


Methods
[modifier] return_type MethodName([parameters]) { … }
• Can be static
• Naming convention: PascalCase

public class BankAccount
{
private readonly string _accountNumber ;
private decimal _balance ;

public void Deposit ( decimal amount )
{
throw new NotImplementedException ();
}
}


Parameter list
• Seperated by a comma
• Have a type and name (camelCase)
• Can be optional
∘ Can have a default value
∘ No value is required when calling the method
∘ Last in the list
public void ExampleMethod (int required , int optionalInt = 10)
{
throw new NotImplementedException ();
}
// Calling this method


9

, Classes CHAPTER 3: MODEL & UNIT TESTING (SOLVING THE PROBLEM DOMAIN)


ExampleMethod (5); // optionalInt will be 10
ExampleMethod (5, 8); // optionalInt will be 8


Named arguments Not every optional parameter may have a value, only specific optional parameter can be
passed to a function using named arguments

public void ExampleMethod (int required , string optionalStr = " default value ",
int optionalInt = 10)
{
throw new NotImplementedException ();
}

ExampleMethod (5, optionalInt : 8);


Passing parameters Parameters can be passed in 3 ways:
• Value parameters

public void Test1 (int x)
{
x += 1;
}
int i = 0;
Test1(i); // i is still 0

• ref parameters
∘ Must write ref when declaring and passing value
∘ Passed variable must be initialized
∘ Every change to the variable’s value will be reflected to the ref parameter

public void Test2 (ref int x)
{
x +=1;
}

int i = 0;
Test2(ref i); // i now has value 1

• out parameters
∘ Must write out when declaring and passing value
∘ Passed variable must not be initialized
∘ The method must assign a value to the out parameter

public void Test3 (out int 3)
{
x = 10;
}

int i = 0;
Test3(out i); // i has now value 10



Passing objects as value parameters, copies the references.
• You can change properties and fields of the object, but not the actual variable’s value. That is only
possible with the ref keyword.

public void Demonstrate1 ( BankAccount bankAccount )
{
bankAccount = null;


10

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller TomDeBakker. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $5.90. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

53340 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$5.90
  • (0)
Add to cart
Added