0

My application uses Domain driven Onion architecture. It has the exact same layers as this.

However, I am a bit confused when I am setting up my IoC dependencies in my mvc app in my client layer. Should I be calling things like my repository interfaces from the client layer or should they be going through the business layer like in a typical 3-tier n-tier application? This way my client layer would only be injecting the business interfaces into it rather than both repository and business interfaces.

If I do end up changing it so the client layer only accesses the business functions I will have to do IoC on the business layer as it uses the data repositories.

William Venice
  • 329
  • 2
  • 7
  • 16

1 Answers1

1

Your client layer should inject instances of the repository interfaces to the business layer, so that the business layer isn't aware of any infrastructure implementation, but has instances that implement the repository interfaces, so it can call the repository through it.

alek kowalczyk
  • 4,896
  • 1
  • 26
  • 55
  • Hmm so can you give me a small example because I don't think I fully understand what your saying. It looks like what you are saying is that my IoC container should only ever be on the client. But I don't fully get what your saying because I am so used to my Client layer only talking to my business layer which only talks to my data layer. – William Venice Oct 17 '15 at 17:02
  • 1
    Yes, because you have the n-tier architecture hardcoded in mind :-) the client layer composes the instances you need and injects them. So you create an XRepository, which implements the IXRepository interface, this interface is referenced by the BL, so you can e.g. inject trough the constructor the XRepository instance to the BL. – alek kowalczyk Oct 17 '15 at 17:34
  • I think it finally clicked. The ICustomerRepository gets passed into the constructor of my mvc controller which gets passed into the constructor of my ICustomerBLL. Therefore I have to resolve dependencies for both the Business and Data interfaces in the client mvc app. Does this make sense? – William Venice Oct 17 '15 at 17:58
  • 1
    Yup, that is the way I'm doing it. To be more precise, I have an additional API layer which does all the dependency injection and instance creation, so that the controllers action are only one-line calls to the API methods. But honestly, I don't think it's needed. Maybe if your api wil be used outside asp.net. – alek kowalczyk Oct 17 '15 at 19:10
  • 1
    Awesome! So your controllers are clean and have very little code. Thanks for the help! – William Venice Oct 17 '15 at 19:22