Best of Dependency Injection2025

  1. 1
    Article
    Avatar of freecodecampfreeCodeCamp·49w

    The NestJS Handbook – Learn to Use Nest with Code Examples

    NestJS is a progressive Node.js framework that combines object-oriented, functional, and reactive programming paradigms to build scalable server-side applications. Built on top of Express or Fastify, it provides a structured architecture using modules, controllers, and providers with built-in dependency injection. The framework offers TypeScript-first development, decorators for routing and validation, middleware support, guards for authorization, exception filters for error handling, and interceptors for response transformation. It includes comprehensive database integration options with TypeORM, Mongoose, and Prisma, along with built-in testing capabilities and CLI tools for code generation.

  2. 2
    Article
    Avatar of jobsJobs·41w

    Domain Driven Design: Key Concepts and Practical Approach

    Domain Driven Design is not about creating domain folders but about modeling code around business responsibilities with clear subdomain boundaries. Each subdomain should handle its own responsibilities and communicate through well-defined interfaces, creating parent-child relationships where domains collaborate through contracts rather than direct dependencies. The approach emphasizes balancing abstraction with practicality, distinguishing between library code (heavily abstracted for reuse) and domain code (tied to specific business contexts).

  3. 3
    Article
    Avatar of milanjovanovicMilan Jovanović·1y

    CQRS Pattern the Way It Should've Been From the Start

    This post explains how to implement CQRS in .NET without relying on MediatR, providing a guide for building a lightweight setup using simple interfaces, decorators, and dependency injection. Explore the benefits such as better control over CQRS infrastructure, predictable dispatching, simplified debugging, and improved testability. Learn how to define command and query interfaces, add decorators for logging and validation, and register everything using Scrutor for a clean and extensible CQRS pipeline.

  4. 4
    Article
    Avatar of javarevisitedJavarevisited·1y

    Only 5% of the Developers Can Answer These Questions! 🚀

    Understanding the fundamentals of Spring Framework is crucial before diving into Spring Boot. This guide emphasizes the importance of core concepts like Dependency Injection, IoC, and Bean Scopes. It presents thought-provoking questions to enhance comprehension and mastery of Spring's capabilities, which are essential for leveraging Spring Boot’s convenience features effectively.

  5. 5
    Article
    Avatar of wendelladrielW endell Adriel·37w

    Inside the Laravel Service Container

    Laravel's Service Container handles dependency injection and auto-wiring by mapping service requests to their implementations. The container supports various binding types (bind, singleton, instance), contextual bindings for different implementations per consumer, auto-wiring through type hints, tags for grouping services, and extension hooks for decorating existing services. Service providers manage the container lifecycle through register and boot phases, while features like method injection and contextual primitives provide flexible dependency resolution.

  6. 6
    Article
    Avatar of freecodecampfreeCodeCamp·35w

    How to Implement Dependency Injection in Go - Explained with Code Examples

    Dependency injection (DI) in Go involves passing dependencies into components rather than creating them internally, making code more testable and maintainable. The guide covers manual DI as the idiomatic Go approach, explains when complexity grows with nested dependencies, and explores DI libraries like Google Wire (compile-time), Uber Dig (runtime), and Uber Fx (with lifecycle management). Manual DI works well for most projects, while frameworks help manage complexity in larger applications. Best practices include keeping dependencies explicit, starting simple, and using interfaces for testability.

  7. 7
    Article
    Avatar of lobstersLobsters·21w

    A SOLID Load of Bull

    A critical examination of the SOLID principles in object-oriented programming. The Liskov substitution principle is endorsed as mathematically sound and universally applicable. The open-closed principle is deemed obsolete in modern languages with proper tooling. The single-responsibility, interface segregation, and dependency inversion principles are criticized as misguided heuristics that lead to over-engineered code. The author argues for focusing on module depth (small interfaces with substantial implementations) rather than blindly following SOLID, and advocates injecting dependencies only when genuinely necessary rather than as default practice.

  8. 8
    Article
    Avatar of tomasvotrubaTomas Votruba·1y

    The Patch for Laravel Container

    The post discusses patching the Laravel Container to optimize performance by ensuring services are treated as singletons rather than being instantiated multiple times. The suggested approach avoids extensive configuration by modifying a single line of code in the Laravel container file. The article highlights the benefits of using patches stored in an open-source repository to simplify the process across projects.

  9. 9
    Article
    Avatar of codigeeCodigee·1y

    Don't mix bloc with get_it

    Mixing Bloc with dependency injection tools like get_it requires careful consideration to avoid issues with state management. Using singletons for BLoC can disrupt its lifecycle, causing unexpected state persistence and errors. Instead, use registerFactory to ensure clean state instances. For better integration, use RepositoryProvider for dependencies within the widget tree.

  10. 10
    Article
    Avatar of collectionsCollections·47w

    Effect: A TypeScript Library That Transforms Backend Development

    Effect is a TypeScript framework for building robust backend applications using generators and advanced TypeScript features. Despite its initially intimidating syntax with function* and yield* patterns, it provides powerful benefits including type-safe error handling, sophisticated dependency injection, and improved observability. The library enables compile-time validation and offers comprehensive modules for concurrency and resource management, making backend applications more reliable and maintainable.

  11. 11
    Article
    Avatar of collectionsCollections·42w

    Understanding Spring Beans: Creation Methods and Best Practices

    Spring Boot provides six primary methods for creating and managing beans through its IoC container, including stereotype annotations (@Component, @Service, @Repository, @Controller), configuration classes with @Bean, component scanning, dependency injection with @Autowired, conditional beans, and profile-specific beans. The framework handles dependency injection automatically, promoting loose coupling and easier testing. Best practices include using constructor injection, leveraging @Primary for bean conflicts, and avoiding manual object creation with the new keyword to maintain proper IoC container management and AOP capabilities.

  12. 12
    Article
    Avatar of freecodecampfreeCodeCamp·27w

    How to Implement Dependency Injection in FastAPI

    FastAPI's dependency injection system uses the Depends() function to deliver reusable logic like authentication, database connections, and validation to path operations. Dependencies can be implemented as functions or classes and injected at three levels: individual endpoints, router groups, or globally across the application. Function dependencies work for most cases, while class dependencies suit stateful logic and object-oriented patterns. The system eliminates code repetition, enables modular architecture, and handles common tasks like authentication guards, logging, rate limiting, and configuration management. Dependencies can execute with or without returning values to path operations, making them flexible for both data retrieval and side-effects.

  13. 13
    Article
    Avatar of csharpcornerC# Corner·43w

    Mastering Dependency Injection in .NET Core: A Complete Beginner-to-Advanced Guide

    Dependency Injection (DI) is a design pattern that promotes loose coupling, testability, and maintainability in .NET Core applications. The guide covers service registration in Program.cs, constructor injection, three service lifetimes (Transient, Scoped, Singleton), testing with mocked services, and advanced scenarios including factory-based registration and third-party containers like Autofac. Best practices include preferring interfaces over concrete classes, avoiding service locator patterns, and organizing registrations by feature modules.

  14. 14
    Article
    Avatar of infoworldInfoWorld·1y

    How to use the IServiceProvider interface in ASP.NET Core

    Learn how to effectively use the IServiceProvider interface in ASP.NET Core to manage dependency injection. Understand the differences between constructor injection and IServiceProvider, explore object lifetimes, and review best practices for using these techniques to improve the maintainability and testability of your applications.

  15. 15
    Video
    Avatar of kantancodingKantan Coding·43w

    The 3 Laws of Writing Testable Code

    Three fundamental principles for writing testable code: use dependency injection to decouple components, leverage interfaces to abstract external dependencies, and separate functions into single responsibilities. Demonstrates these concepts through a payment processing example, showing how to isolate code from external APIs like Stripe for effective unit testing.

  16. 16
    Article
    Avatar of jetbrainsJetBrains·48w

    Ktor 3.2.0 Is Now Available

    Ktor 3.2.0 introduces significant new features including dependency injection module, HTMX integration, typed configuration deserialization, Unix domain socket support for CIO engine, and Gradle version catalog support. The release also adds suspend modules for asynchronous initialization and improved integration with existing DI frameworks like Koin. Notable improvements include automatic configuration file deserialization into data classes and enhanced HTML attribute handling for HTMX applications.

  17. 17
    Article
    Avatar of tiaThis is Angular·1y

    Angular's inject function: a couple of years later...

    Angular's `inject` function, introduced in Angular 14, offers an alternative to constructors for injecting dependencies. It simplifies inheritance, reduces boilerplate code, eliminates the need for parameter decorators, and provides more concise and type-safe code. However, it can lead to scattered and hidden dependencies, making testing and code comprehension more challenging. Understanding the Injection Context is crucial for using `inject` effectively. Despite some concerns, `inject` has proven useful and is recommended over constructor parameters for consistent coding practices.

  18. 18
    Article
    Avatar of tiaThis is Angular·1y

    Dynamic Service Instantiation In Angular

    Dynamic service instantiation in Angular can be leveraged to defer the creation of services based on user selections, thus optimizing performance. This approach is useful when integrating third-party services or when runtime decision-making is needed. Examples include dynamic formatters, file upload handlers, notification services, and authentication providers. Using Angular's Injector, services are created only when required, avoiding the overhead of unnecessary initializations.

  19. 19
    Article
    Avatar of colkgirlCode Like A Girl·34w

    When to use the different types of Dependency injection systems in .Net

    Explains the three dependency injection service lifetimes in .NET Core: AddTransient (creates new instance every time), AddScoped (one instance per request), and AddSingleton (one instance for entire application). Uses practical analogies like coffee ordering and restaurant plates to illustrate concepts, followed by a hands-on code example demonstrating the differences in behavior.

  20. 20
    Article
    Avatar of lnLaravel News·44w

    Singleton and Scoped Container Attributes in Laravel 12.21

    Laravel 12.21.0 introduces singleton and scoped container attributes that can be applied directly to classes without manual registration. The release adds a whereValueBetween() query builder method for checking if values fall between two columns, strict validation options for numeric and boolean types, factory relationship controls, URI stringable conversion, and fluent empty check methods.

  21. 21
    Article
    Avatar of andrewlock.NET Escapades·1y

    Going beyond singleton, scoped, and transient lifetimes

    The post explores experimental dependency injection scopes beyond the standard Singleton, Scoped, and Transient lifetimes in .NET Core. It discusses hypothetical lifetimes such as tenant-scoped, pooled, and time-based (drifter) services, inspired by a podcast discussion. The post details implementations of these lifetimes, focusing particularly on time-based services, and highlights their characteristics and limitations. The implementation challenges, particularly with IDisposable services, are also covered.