© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4mo ago•
6 replies
Thalnos

Inject multiple implementations of the same interface

what's the proper way to inject multiple implementations of the same interface?
public class FooBar{
     public FooBar(IInterface something){

     }
}
builder.Services.AddScoped<IInterface, Implementation1>();
builder.Services.AddScoped<IInterface, Implementation2>();
public class FooBar{
     public FooBar(IInterface something){

     }
}
builder.Services.AddScoped<IInterface, Implementation1>();
builder.Services.AddScoped<IInterface, Implementation2>();

is a setup like this possible? Which one is being injected? How to have different classes use different impelmentations without them using concrete dependencies of Implementation1 and Implementation2?
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

Query over multiple entities using the same interface [Answered]
C#CC# / help
4y ago
Confused about interface default implementations [Answered]
C#CC# / help
4y ago
❔ Route returning multiple of the same item.
C#CC# / help
3y ago
✅ The interface has static abstract members without implementations. How to fix?
C#CC# / help
6mo ago