1

I am new to DI containers and have been doing some reading and I was wondering if you guys could help me out with my first sample project.

I have a MVC5 application separated into n tier modules. I have my presentation module injecting an IDataAdapter into a controller via a defaultcontrollerfactory. This dataadapter is then passed via constructor injection into a service class that talks to the data access layer via the IDataAdapter.

My question is, where is the IDataAdapter interface class supposed to be located, obvious the concrete class that implements this interface needs to be in the data access layer. I could leave the interface in the DAL, but then I would need a hard reference between my view and dal, and that does not seem right.

So I made a separate project library to hold my container logic and data adapters, but now I am running into a circular dependency, where my DataAdapter needs to implement the IDataAdapter interface, but my unity registration file does not know what the DataAdapter concrete class is because it can’t reference the DAL.

anon582847382
  • 19,907
  • 5
  • 54
  • 57
Xearo
  • 85
  • 1
  • 11
  • As Agile Principles, Patterns, and Practices explain in chapter 11, **"clients […] own the abstract interfaces"**. http://amzn.to/19W4JHk – Mark Seemann Mar 08 '14 at 22:13
  • See also http://stackoverflow.com/a/9503612/126014 – Mark Seemann Mar 08 '14 at 22:16
  • 3
    The short answer is that the client should define *the interface it needs*, which is almost certainly *not* something like `IDataAdapter`, which sounds like a **Leaky Abstraction**. See http://stackoverflow.com/a/22164792/126014 for a related discussion. – Mark Seemann Mar 08 '14 at 22:23

1 Answers1

0

While using dependency Injection, It would be good to have all interfaces in a separate assembly so that you can avoid any kind of circular dependency.

High level diagram of recommended solution structure:

Click here to see high level diagram of recommended solution structure

Matt
  • 74,352
  • 26
  • 153
  • 180
  • Please disclose your affiliation with sites when you link to them. For more info, see http://stackoverflow.com/help/promotion – Matt Sep 16 '16 at 12:23