Click here to Skip to main content
15,886,798 members
Everything / Dependency injection

Dependency injection

dependency-injection

Great Reads

by Nick Polyak
Describes how to install dynamically loaded plugins as nuget packages
by Chris Copeland
A managed library for automated dependency injection, contract validation, and custom aspect-oriented decorator implementations
by GerVenson
Why do we need to register all services with service.AddService?
by Tom Ling
The code for this example can be found here. What is dependency injection. Dependency injection (DI) is a software design pattern that allows developers to write loosely coupled code.

Latest Articles

by Federico Alterio
How to optionally inject a dependency using Microsoft DependencyInjection container
by Dev Leader
Jumpstart app with Autofac
by Nick Polyak
Describes how to install dynamically loaded plugins as nuget packages
by Jason Sultana
How to add configuration to Web API and other project types

All Articles

Sort by Score

Dependency injection 

17 Jan 2023 by Nick Polyak
Describes how to install dynamically loaded plugins as nuget packages
9 Jun 2020 by Chris Copeland
A managed library for automated dependency injection, contract validation, and custom aspect-oriented decorator implementations
30 Aug 2021 by GerVenson
Why do we need to register all services with service.AddService?
6 Jun 2019 by Tom Ling
The code for this example can be found here. What is dependency injection. Dependency injection (DI) is a software design pattern that allows developers to write loosely coupled code.
23 Apr 2020 by Pete O'Hanlon
There are a series of articles here on CodeProject that answer this question. The first part can be found here: Dependency Inversion Principle, IoC Container, and Dependency Injection: Part 1[^] Most IoC containers provide similar implementations.
31 Jul 2021 by Jason Sultana
Using builder pattern to help unit testing a service with more than just a couple of dependencies
8 Nov 2019 by Petru Faurescu
Simplified guide to building a fast, secure web application backend
13 Jan 2020 by M.M.Mohseni
In this article, we'll explain how to register (Add) all specific interface assignable types in an assembly and will use them in a class.
23 Apr 2020 by Maciej Los
Another resources: Dependency injection in ASP.NET Core - lifetimes[^] .NET Core Dependency Injection Lifetimes Explained - .NET Core Tutorials[^] Dependency Injection Lifetime: Transient, Singleton & Scoped - TekTutorialsHub[^]
16 Apr 2019 by Petru Faurescu
What’s about Problem / solution format brings an easier understanding on how to build things, giving an immediate feedback.
5 Dec 2019 by Richard Deeming
Hosted services are registered as singletons, and cannot directly depend on scoped services. If an instance of a scoped services was injected into a singleton service, it would become a singleton itself. Captive Dependency[^] The dangers and gotchas of using scoped services in...
17 Jan 2022 by _Asif_
Check this: Article is doing the same thing .NET Core Dependency Injection with Configuration – csharp.christiannagel.com[^]
17 Jan 2022 by Magnus Sydoff
I finally gave up Googling this issue and took a deep look on how the automatic variant of injecting services was made. I used this NuGet package, AutoRegisterDI[^] as a starting point and ended up something looking like the code below (some of...
7 Aug 2022 by Jason Sultana
How to add DI to your .NET console apps
13 Nov 2018 by Vlad Neculai Vizitiu
Let’s talk about MEF – Part 1
13 Nov 2018 by Vlad Neculai Vizitiu
What an Inversion of Control (IoC) container is and how it works
13 Nov 2018 by Vlad Neculai Vizitiu
In this post, we will take a deeper look at what Dependency Inversion or Dependency Injection actually means and how it helps us.
16 Apr 2019 by Member 13074421
I have tried dependency injection example from here https://dzone.com/articles/guicing-play-framework What is missing here? What I have tried: public class TestController extends Controller{ @Inject private Testing test; public Result result() { test.tt(); return ok(); } } ...
30 May 2019 by titu-1670319
Hi I am using unity container for depency injection by attributes using following code container.RegisterTypes( AllClasses.FromLoadedAssemblies() .Where(t => t.GetCustomAttributes(true).Any()), ...
30 May 2019 by Gerry Schmitz
Quote: Problem is sometimes i get following exception which goes if i clean and rebuild the solution. am i missing something ? Yes. You're missing another clean and rebuild.
23 Aug 2019 by ravithejag
I want to pass an extra parameter while resolving the dependencies based on the type. please have a look into my code changes private readonly Func _strategyFactory; calling the stratergy pattern to resolve the dependencies based on the Type. return _strategyFactory(...
25 Aug 2019 by Member 11380736
I'm trying to create a dynamic architecture for a Audio/Video player application. I want to be able to change the type of playlist and type of repository from inside the ioc container. This should be injected in constructors around the application: IPlaylist playlist,...
5 Dec 2019 by Member 14615490
Hi I am working on worker service asp.net core 3.0 . I am getting the following error: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostedService Lifetime: Singleton ImplementationType:...
13 Jan 2020 by M.M.Mohseni
In this article, you will learn how to write a new extension for .Net Core DI and register all assignable types in an assembly with specific interface.
3 Nov 2020 by Member 14983007
I have a few functions in my main method for my python application. All these functions perform various tasks by calling different classes under my src folder. Applications using my tool define a configuration file that my tool reads from and...
30 Nov 2020 by xhon
I'm on a ASP NET MVC 5 web application inside a multi-tier solution. The general scenario is the following: the controller Mvc uses a proxy to call methods from the services (Rest and Service2), the services call the methods from the business...
19 Dec 2020 by Reza kavian
i want to autorize in controller action via RedirectingAction class. When I call this class above the Home/Privacy, I just want to enter the type and value of the claim to check, but I do not set the IHttpContextAccessor object. i want set value...
4 Feb 2021 by Member 11352015
I am new to using Castle Windsor I have a couple of registered dependencies using Castle Windsor. I would like to dispose and remove one of these injected dependency at a particular time. How can I do this. My code is as follows: In the main...
4 Feb 2021 by Richard Deeming
Remove component in CastleWindsor version >3.0 · Issue #151 · castleproject/Windsor · GitHub[^] Looks like it was broken in 5.1.0, but it should be working again in 5.1.1: DefaultNamingSubSystem.InvalidateCache was protected and has been made...
4 Oct 2021 by Member 12885549
From definition: > Inversion of Control (IoC) means to create instances of dependencies first and latter instance of a class (optionally injecting them through constructor) is then it a good example of DI and IoC? Meaning that I create instance...
7 Dec 2021 by nidhi shankhdhar
I am writing a library which user can reuse to connect with multiple APIs. Requirement is to create multiple Typed client using IHttpClientFactory based on configuration in appsettings.json. I am reading Typed client from config so unable to...
7 Dec 2021 by Richard Deeming
With the IHttpClientFactory, you can either have a standard HttpClient keyed by name, or a typed client keyed by type. There is no support for registering different versions of the same typed client. How about something like this? public...
3 Sep 2022 by Magnus Sydoff
Hello all, I have used Autofac to write a Console application in Net6 for Windows, Ubuntu and Raspberry. I have managed to wire up my dependencies using an external json file for Autofac as shown below. protected override void...
17 Jan 2022 by Magnus Sydoff
Using .NET Core 6 dependency injection I have code in Program.cs looking like this ... IConfigurationBuilder configuration = new ConfigurationBuilder(); configuration.SetBasePath(Directory.GetCurrentDirectory()); var host =...
17 Jan 2022 by OriginalGriff
Repost: Deleted. Please do not repost your question; use the Improve question widget to add information or reformat it, but posting it repeatedly just duplicates work, wastes time, and annoys people. I'll delete this one.
9 Aug 2022 by Philippe Monteil
Core concepts and mechanisms of Microsoft.Extensions.DependencyInjection Dependency Injection
3 Sep 2022 by TimWallace
You could register factories instead of classes with the DI container. Then have the factories create the instance(s) from config file settings.
3 Sep 2022 by Magnus Sydoff
In order to solve the problem I finally ending up writing something like the code below. First some module definitions public static string ModulesFolderName = "Modules"; public interface IModuleDataConfiguration { ...
25 Jan 2023 by Member 12799321
I am using Asp.net webapi with c# framework 4.7 with those I am trying to handle the apseeting.json file using Calabonga.Configuration package I don't know how can I register class instance that depends on multiple interfaces in unity container....
3 Nov 2023 by rw-MassimoTamburini
We are building a WPF application using Microsoft.Extensions.DependencyInjection and we would like to change a little bit the structure that we have now. Our WPF pages use viewmodels and communicate with the business logic layer using commands...
4 Apr 2017 by ashish__shukla
The post Dependency Injection using Unity container appeared first on codecompiled .Dependency injection is one way to implement inversion of control.To understand dependency injection please refer Dependency Injection in .NET Dependency injection injects the dependencies of a class at runtime.This
9 Aug 2022 by Mark Pelf
We explain DI Pattern, DIP, IoC, DI Container
12 Feb 2022 by Aly Elhaddad
Introduction and documentation for new ThunderboltIoc framework that achieves DI in .NET without reflection
23 Apr 2017 by Habibur Rony
This article is about dependency, type of Dependency, its use, advantages and disadvantages; as well as it will cover Dependency Inversion, Inverse of Control, and IOC Framework.
3 Feb 2019 by Vlad Neculai Vizitiu
How to use claims following a typed approach
10 Mar 2019 by Fred Song (Melbourne)
Angular 7 with .NET Core 2.2 - Global Weather (Part 2)
10 Aug 2022 by Jason Sultana
How to add configuration to Web API and other project types
11 Jun 2023 by Federico Alterio
How to optionally inject a dependency using Microsoft DependencyInjection container
26 Oct 2020 by Matteo Prosperi
Being an engineer on the AWS SDK for .NET team, I tasked myself with figuring out how to use our libraries under Blazor in the browser.
4 Mar 2019 by marcusts
They got it wrong with IOC containers, but that can be fixed. The post A Smarter DI Container for Xamarin.Forms appeared first on Marcus Technical Services.
21 Jan 2023 by Dev Leader
Jumpstart app with Autofac
14 Nov 2018 by Vlad Neculai Vizitiu
Hello and welcome to part two of the use and abuse of the C# modifier keywords, Last time we looked at the access modifiers that apply to types (class, struct, and enums) and members (fields, methods, nested classes, etc.
23 Apr 2020 by 855
how does .net core implement dependency injection for different lifetimes? how does a instance created and disposed for different lifetimes? What I have tried: What i could think is 1.singleton - use a global static dictionary to keep all the...