.NET Development Guide

website·Indexed 31 days ago

https://dotnet.a-nomad.com/

A comprehensive technical guide covering ASP.NET Core and .NET development. Topics include Dependency Injection (DI) with ServiceLifetime (Singleton, Scoped, Transient), routing, middleware pipelines, authentication and authorization using JWT and Identity Server, EF Core data access, and configuration frameworks. It also provides details on WebAPI, OpenAPI, multi-version management, and performance optimization through caching and page staticization.

Tokens
79.1K
Snippets
314
Records
396
Agent score
52%

What's inside .NET

  1. Overview of .NET Configuration Framework

    The .NET configuration system provides a lightweight, extensible way to read configuration data from multiple sources using a consistent programming model. It relies on three core components: IConfigurationSource (defines the data source), IConfigurationBuilder (collects sources and builds the configuration), and IConfiguration (the resulting object used to access settings). Configuration is fundamentally treated as a set of key-value pairs, where both keys and values are strings, though they can be organized in a hierarchical structure.
  2. Overview of Dapper ORM

    Dapper is a lightweight, semi-automatic ORM framework for .NET. Unlike Entity Framework or NHibernate, it does not use complex configuration files and requires developers to define their own entity classes. It works by providing extension methods for the IDbConnection interface and supports any database compatible with ADO.NET, including SQLite, SQL CE, Firebird, Oracle, MySQL, PostgreSQL, and SQL Server.
  3. Overview of the .NET Options Pattern

    The Options pattern in .NET allows developers to bind configuration settings to POCO objects and inject them into services via Dependency Injection (DI). This implements the Interface Segregation Principle (ISP) and Separation of Concerns (SoC), ensuring services only depend on the specific configuration they need rather than the entire configuration framework or data source.
  4. Overview of the .NET Framework

    .NET is a general-purpose, open-source, and cross-platform development framework used to build modern, scalable, and high-performance applications. It supports multiple programming languages including C#, VB.NET, F#, XAML, and TypeScript. It is compatible with Windows, Linux, and macOS across various architectures (x64, x86, and ARM).
  5. Overview of .NET File Provider abstractions

    The .NET File Provider system provides a hierarchical directory structure abstraction that shields developers from the underlying file system implementation. The core types located in Microsoft.Extensions.FileProviders.Abstractions are:

    • IFileProvider: The main interface for accessing files and directories.
    • IFileInfo: Represents a file or directory. Use IsDirectory to check if it is a folder and Exists to verify its presence. If it is a file, Length and CreateReadStream() are available.
    • IDirectoryContents: Represents the contents of a directory.
    public interface IFileProvider
    {
        // Gets information for a specific file
        IFileInfo GetFileInfo(string subpath);
    
        // Enumerates the contents of a specific directory
        IDirectoryContents GetDirectoryContents(string subpath);
    }
  6. Overview of the ELK Stack

    ELK is a classic distributed logging framework consisting of three open-source components:

    • Elasticsearch: A distributed search engine used for collecting, analyzing, and storing data. It features automatic discovery, index sharding, and a RESTful API.
    • Logstash: A tool for collecting, analyzing, and filtering logs. It typically uses a client/server architecture where clients collect logs and the server filters/modifies them before sending them to Elasticsearch.
    • Kibana: A web interface for visualizing and searching log data provided by Logstash and Elasticsearch.
  7. Introduction to Unit Testing and TDD

    Unit testing involves verifying the correctness of the smallest testable parts of an application, such as individual programs, classes, objects, or methods. The goal is to define expected inputs and outputs before writing the code to ensure the implementation meets requirements.

    Test-Driven Development (TDD) is a core agile practice where test cases are written before the functional code. The developer then writes the minimum amount of code necessary to pass the test, iterating until the requirement is fully met.

  8. Understand the role of IdentityServer in OAuth2 and OIDC

    IdentityServer (also referred to as an Identity Provider, Security Token Service, or Authorization Server) acts as a central authority for security and authentication. Its primary responsibilities include:

    • Protecting resources (User identity information or API resources).
    • Performing identity authentication using local accounts or third-party providers.
    • Providing session management and Single Sign-On (SSO).
    • Managing and authenticating client applications.
    • Issuing Identity Tokens and Access Tokens to clients.
    • Validating tokens.
  9. Understand .NET Service Registration basics

    Service registration in .NET is the process of creating ServiceDescriptor objects and adding them to an IServiceCollection. Crucially, services are not instantiated during registration; instantiation only occurs when a service instance is requested from the container via ServiceProvider.GetService<T>.
  10. Understand the Hybrid flow in OpenID Connect

    The Hybrid flow is an OpenID Connect authorization method that combines the Authorization Code and Implicit flows. It always returns an Authorization Code to the client browser after successful authentication. Depending on the ResponseType configuration, it can return different token combinations: Code/Id Token, Code/Token, or Code/Id Token/Token. Because it requires an Authorization Code, it is typically used to protect confidential clients. Note that oidc-client-js does not support the Hybrid flow.
  11. Understand the .NET Logging Model (ILogger, ILoggerFactory, ILoggerProvider)

    The .NET logging model consists of three core components defined in Microsoft.Extensions.Logging.Abstractions:

    1. ILogger: The interface used by applications to dispatch log events. It acts as the 'publisher'.
    2. ILoggerProvider: A provider that creates specific ILogger implementations. These implementations are the 'consumers' that actually write the logs to a specific destination (e.g., Console, File, Database).
    3. ILoggerFactory: A factory that manages ILoggerProvider instances. When the application requests an ILogger from the factory, it returns a composite Logger object that distributes the log event to all registered providers.

    In summary: ILoggerFactory creates a dispatcher (Logger), which in turn forwards events to the actual output implementations provided by ILoggerProvider.

  12. Understand Managed vs. Native Threads

    In .NET, threads are categorized into two types:

    • Native Threads: Managed directly by the operating system. They involve 'context switching' (saving/restoring CPU registers), which is a costly operation.
    • Managed Threads: A unified threading model built by .NET on top of native threads. A managed thread (represented by a Thread object) can be associated with zero or one native thread. Managed code must execute within a managed thread.