Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Can we also use simple injector with unity pattern?
Can we also use simple injector with unity pattern? Aspnet core provides interface usage. However in simple injector we have passed just repository to the container. (no interface) What is the advantage of using interface together with DI?
James ChurchillTreehouse Teacher
Thanks for your question. I started with showing registering concrete types with the Simple Injector DI container in order to keep the examples as simple as possible. All of the popular .NET DI containers, including Simple Injector, support registering concrete types or registering interface/concrete type mappings.
The main benefit of registering interfaces with the DI container is that dependent classes (like our controller in the ASP.NET Core example) only take a dependency on the interface and not on a specific concrete type. This further improves the loose coupling between classes. And it allows you to easily replace the concrete type that the container will instantiate for that interface by changing the concrete type in your container configuration that's associated with that interface.