© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
56 replies
__dil__

❔ Dependency Injection

Disclaimer: I come from a low-level language, never did Java and very new in C#.

I started to read the Avalonia UI MVVM tutorial, and it mentioned that usually you'd use DI to avoid coupling the model and the viewmodel.

This got me curious about what exactly is DI. My understanding is that you have a service that uses a dependency. Instead of using the dependency directly, you make the service use an interface for that service, and provide an instance of that interface somehow.

So, the "replace concrete type with interface" I get.

My main confusion is about how to provide the instance. From what I read, it's either

1) passing a concrete type instance to a constructor that expects the interface type.

Or

2) Something involving "frameworks and "automatic registration".

Option 1) is pretty intuitive, not much to be confused about here, but option 2) is complete gibberish to me.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Dependency injection
C#CC# / help
6mo ago
✅ Dependency injection
C#CC# / help
2y ago
Dependency Injection Question
C#CC# / help
12mo ago
Dependency Injection question
C#CC# / help
17mo ago
Next page