resources

C#.NET Training: Resources

Contents

Fundamentals

C# is a object-oriented and type-safe programming language. C# enables developers to build many types of applications that run in .NET.

C# programs run on .NET, a virtual execution system called the common language runtime (CLR) and a set of class libraries. The CLR is the implementation by Microsoft of the common language infrastructure (CLI), an international standard.

What is .NET? .NET is a free, open-source development platform for building many kinds of apps, such as:

Types and variables

A type defines the structure and behavior of any data in C#. The declaration of a type may include its members, base type, interfaces it implements, and operations permitted for that type. A variable is a label that refers to an instance of a specific type.

There are two kinds of types in C#: value types and reference types. Variables of value types directly contain their data. Variables of reference types store references to their data, the latter being known as objects. With reference types, it’s possible for two variables to reference the same object and possible for operations on one variable to affect the object referenced by the other variable. With value types, the variables each have their own copy of the data, and it isn’t possible for operations on one to affect the other (except for ref and out parameter variables).

An identifier is a variable name. An identifier is a sequence of unicode characters without any whitespace. An identifier may be a C# reserved word, if it’s prefixed by @. Using a reserved word as an identifier can be useful when interacting with other languages.

C#’s value types are further divided into simple types, enum types, struct types, nullable value types, and tuple value types. C#’s reference types are further divided into class types, interface types, array types, and delegate types.

C# programs use type declarations to create new types. A type declaration specifies the name and the members of the new type. Six of C#’s categories of types are user-definable: class types, struct types, interface types, enum types, delegate types, and tuple value types. You can also declare record types, either record struct, or record class. Record types have compiler-synthesized members. You use records primarily for storing values, with minimal associated behavior.

Object Oriented programming

Working Mode

The road-map consists of several steps. In each step, a set of theoretical concepts are explored, supported by reference documentation, book chapters, tutorials and videos. In parallel, a simple application will be built with the learned concepts: the Online Shop application.

After the learning material for a given step was sufficiently explored, either some new functionality will be added to this application or old functionality will be refactored.

The application will have little-to-no user interface. Developers are expected to perform developer tests with Postman once the REST APIs are implemented OR Swagger

All the code written must be published on GitHub. Commits must be pushed when each individual chapter is finished. In order to request a code review from the trainers, you must open a pull request from the develop to the master branch.

Environment

You can work using your local environment:

Online Shop

The application will deal with the management and daily functioning of a small online shop. Business processes:

Data Model

Chapters

0. Prerequisites

Goal: Getting familiar with the ecosystem around c#. You can skip this chapter if you have already worked with C# and Git.

Required Reading:

Online Shop: nothing to do.

Further Resources:

1. WEB API

1.1. Create Web API project

For the first chapter please create a simple Web API using .Net Core. To create the application open Visual Studio, choose a Create a New Project, Select ASP.NET Core Web API project and follow the steps. Please check the following the images to select the right options: Data Model and Data Model

After you create the project please inspect all the classes that were made. In the project create the Folder Model where you will put your data Model. As a start-up sample, you have in Sources/Chapter1/Startup_Chapter the project created with one class implemented.

You should create the rest of the data models and controls. The classes are shown below diagram: Data Model Location, ProductCategory collection should be implemented as a generic “HashTable”. Location, ProductCategory will have a controller. Stock will not have a controller.

Online Shop:

Register an account on GitHub and accept the training GitHub Classroom Assignment. This will create a new GitHub repository for you. Clone this repository locally and checkout the develop branch. During the course of the training, you will commit and push your work on this branch.

Go to “Visual Studio” and generate a new project ASP.NET Core Web API:

1.2. Test your app

Goal: Debug and testing your aplication.

The online shop application built on Cpater 1 has included the Kestrel server inside. The Kestrel web server is a new web server as part of ASP.NET Core. It is now the preferred web server for all new ASP.NET applications. By default, Kestrel will generate a test page for your application. This is a good starting point to do manual testing of your application.

Look at the screenshots from folder /Sources/Chapter2 to see how you can test your application.

Online Shop:

(Optional) For other type of testing, you can use different tools like:

1.3. Local drive access

Goal: Understand IO Operations and JSON Serialization

Required Reading:

OnlineShop: Save product information and order information on local json files on disk.

Further Reading:

1.4. Logging

Goal: Understand how logging libraries work and how to log the necessary information from your application

Required Reading:

Online Shop: Logging important actions (Order Product, Product create/edit/delete and so on) will greatly assist in the support and development of your application.

Future Reading:

1.5. Exception Handling

Goal:

Required Reading:

Online Shop:

2. Database access

Goals: a) Understanding the need and advantages of databases compared to the file system. b) Principles of databases. c) Understanding, comparing, contrasting, using and integrating different database frameworks into a web application. e) Choosing and using relational and non-relational databases.

Why databases?

Required reading: File System vs. Database

Online Shop: Ask yourself the following questions: what happens if you want to update a numeric quantity into a very large products/orders data file that stores online shop information? What happens if during the time spent with reading/searching a large file, other simultaneous requests come for writing or modifying or deleting the same quantities or entries and what happens if during that exact time there is a power shortage? Can databases address some of these problems?

Further reading: Why use a database instead of saving data to disk?

2.1. Entity Framework

Goal: Understanding how and why Entity Framework can be used to automate all types of SQL database-related activities for an application, and how using the frameowrk developers can work at a higher level of abstraction when they deal with data and can create and maintain the data-oriented application with less code and database-related knowledege.

Required Reading: .NET 6.0 - Connect to SQL Server with Entity Framework Core

Online Shop: Automatically create/update an SQL Server database from code using EF Core migrations that mirrors the model from Chapter 1 based upon the example given in the previous tutorial and adapt given example to connect, control & manage and perform CRUD operations on the SQL DB.

Further Reading:

2.2. ADO.NET

Goal: Understanding how ADO.NET provides consistent access to data sources such as SQL Server and how data-sharing consumer applications can use ADO.NET to connect to these data sources and retrieve, handle, and update the data that they contain.

Required Reading: ADO.NET by building CRUD features in ASP.NET Core Application

  1. Learn ADO.NET by building CRUD features in ASP.NET Core Application
  2. Create Records using ADO.NET in ASP.NET Core Application
  3. Read Records using ADO.NET in ASP.NET Core Application
  4. Update Records using ADO.NET in ASP.NET Core Application
  5. Delete Records using ADO.NET in ASP.NET Core Application
  6. SqlBulkCopy class of ADO.NET

Online Shop: Create an SQL database that mirrors the model from Chapter 1 based upon the example given in the previous tutorials and adapt and test given example to connect, control & manage and perform CRUD operations on the SQL DB.

Further Reading:

2.3. MongoDB

Goal: Understanding the difference between a relational and a non-relational database and adapting the OnlineShop Web Api to have persistence into a NoSql model database such as MongoDb.

Required Reading:

Online Shop: Create a MongoDB NoSQL database that mirrors the model from Chapter 1 based upon the example given in the previous tutorial and adapt and test given example to connect, control & manage and perform CRUD operations on the DB.

Further Reading:

3. Create interface for data access

Below are described 3 methods on how to access the database using c#, depending on the implementation, you can choose to use desktop or web applications to access the database.

3.1. Using Angluar vs. React vs. Vue

There are three frameworks for building web applications that every frontend developer has heard about: React, Vue, and Angular. React is a UI library, Angular is a fully-fledged front-end framework, while Vue.js is a progressive framework. They can be used almost interchangeably to build front-end applications, but they’re not 100 percent the same, so it makes sense to compare them and understand their differences. Each framework is component-based and allows the rapid creation of UI features.

3.3. Using Razor vs. Blazor

4. Security

Code access security is a mechanism that grants/denies access to resources within a method call. For example, code written by a person may be allowed to write to the disk while code from another one may be forbidden from accessing the disk. This control can be enforced even if the code written by both of them is used within a single application.

C# security vulnerabilities includes topics such as :

Goal: Group business logic into service classes and expose this logic through REST interfaces.

Required Reading:

Online Shop:

Create a simple API for exposing the products and product categories:

Create a service class that handles the creation of orders. The following constraints apply:

Create a Rest Controller for the “Create order” operation, which should have a POST mapping accepting a JSON request body and producing a JSON response body.

Further Resources:

OPT-1. ODBC

OPT-2. MongoDB

Goal: Store unstructured data in a NoSQL database.

Required Reading:

Further Resources:

OPT-4. RabbitMQ

Goal: Asynchronously communicate with a background worker application.

Required Reading:

Further Resources:

OPT-5. WebSocket

Goal: Publish events though WebSocket to allow potential user interfaces to automatically update their displayed data.

Required Reading:

Online Shop:

Further Resources: