© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
18 replies
Drunkreaper

Is it possible to create a dependency injection with interface and an abstract(base) class?

So im building a controller that uses IPersonFactory<T> to connect to PersonFactory<T> which is a base class that depending on the generic type sends the request to several different sub-factories which ultimately end in respective repositories.

Rn I'm downcasting _factories to different generic types of IPersonFactory<Person> to do the type change.

Since this gives a build error would it be better to make fields for all different types of IPersonFactory and make injections for them?
image.png
image.png
image.png
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

✅ Abstract Class vs Interface
C#CC# / help
10mo ago
❔ abstract class vs interface
C#CC# / help
3y ago
Mocking derived class with abstract base class
C#CC# / help
4y ago
ELI5 : Abstract Class vs Interface
C#CC# / help
2y ago