Code Explainers
Code explainers tagged #dependency-injection
python
from fastapi import APIRouter, Depends, HTTPException, status from app.config import settings from app.dependencies import get_current_user
Gating a FastAPI route behind a feature flag
feature-flags
dependency-injection
authorization
Intermediate
7 steps
python
import csv import io from typing import Annotated
Content negotiation in FastAPI
content-negotiation
dependency-injection
http-headers
Intermediate
5 steps
typescript
import { Routes } from '@angular/router'; import { inject } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { REPORT_API_URL } from './reports/report.tokens';
Route-scoped providers and lazy loading in Angular
routing
dependency-injection
lazy-loading
Intermediate
8 steps
typescript
import { Component, inject } from '@angular/core'; import { combineLatest, map, startWith } from 'rxjs'; import { UserStore } from './user.store'; import { CartStore } from './cart.store';
The view model pattern in Angular
rxjs
view-model
reactive-streams
Intermediate
6 steps
python
from fastapi import APIRouter, status from fastapi.responses import JSONResponse from sqlalchemy import text from sqlalchemy.exc import SQLAlchemyError
Liveness vs readiness health checks in FastAPI
health-checks
dependency-injection
async
Intermediate
6 steps
typescript
import { Injectable, UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { Strategy } from 'passport-headerapikey'; import { ConfigService } from '@nestjs/config';
Building an API-key auth strategy in NestJS
authentication
passport
dependency-injection
Intermediate
8 steps
python
from typing import Optional from fastapi import APIRouter, Depends, HTTPException, status from pydantic import BaseModel, EmailStr, Field
How PATCH partial updates work in FastAPI
partial-update
validation
dependency-injection
Intermediate
8 steps
python
from fastapi import APIRouter, Depends, HTTPException, status from pydantic import BaseModel from .dependencies import get_current_user, get_project_service
Building a CRUD router with FastAPI
dependency-injection
rest-api
authentication
Intermediate
6 steps
typescript
import { Component, inject } from '@angular/core'; import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms'; import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { finalize } from 'rxjs';
A reactive signup form in Angular
reactive-forms
validation
dependency-injection
Intermediate
10 steps
rust
use std::sync::Arc; use axum::{ extract::{FromRef, State},
Substate extraction with FromRef in Axum
state-management
routing
middleware
Intermediate
8 steps
typescript
import { InjectionToken, inject, Provider, isDevMode } from '@angular/core'; import { WINDOW } from './window.token'; export interface AnalyticsConfig {
Layered config with an Angular InjectionToken
dependency-injection
configuration
factory-provider
Intermediate
8 steps
java
@RestController @RequestMapping("/api/products") @Validated public class ProductSearchController {
Validating query params in a Spring controller
validation
pagination
rest-api
Intermediate
8 steps
python
import secrets from fastapi import Depends, FastAPI, HTTPException, Security, status from fastapi.security import APIKeyHeader
API key authentication as a FastAPI dependency
authentication
dependency-injection
api-keys
Intermediate
8 steps
java
@Component public class HeaderMergeFilter { private static final String PER_REQUEST_HEADERS = HeaderMergeFilter.class.getName() + ".headers";
Merging default and per-request headers in Spring
webclient
filters
http-headers
Intermediate
8 steps
typescript
import { Injectable, inject } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, timer, throwError } from 'rxjs'; import { switchMap, takeWhile, filter, take, catchError } from 'rxjs/operators';
Polling a job until it finishes in Angular
rxjs
polling
observables
Intermediate
7 steps
php
<?php namespace App\Http\Controllers;
Handling Stripe webhooks in Laravel
webhooks
signature-verification
dependency-injection
Intermediate
7 steps
typescript
import { Injectable, signal, computed, effect, inject } from '@angular/core'; import { DOCUMENT } from '@angular/common'; export type Theme = 'light' | 'dark';
A signal-based theme service in Angular
signals
reactivity
dependency-injection
Intermediate
7 steps
java
@Component public class RegionCacheWarmer implements SmartInitializingSingleton { private static final Logger log = LoggerFactory.getLogger(RegionCacheWarmer.class);
Warming a Spring cache at startup
caching
startup-hook
dependency-injection
Intermediate
7 steps