2

Can any body explain how to set dependency between layers in layers based architecture using DI IOC and also please explain when we create Composition root in the UI layer then we need to refer all the dll in UI layer this leave the scope for UI developer to access DAL layer object directly. This will breach the the rule where UI layer should not be able to access DAL object directly.

Can any architect SME explain what is the correct way of Implementing Layered based architecture using below mention technology stack.

Here the technology preference is ASP.NET MVC 4, REST API Service, Enterprise library ( Repository pattern)

sameer
  • 1,635
  • 3
  • 23
  • 35

3 Answers3

1

I think this is the difference between UI Layer "should not" access the DAL layer, and "can not". It would be complicated indeed to enforce the layering such that the DAL is truly inaccessible to the UI layer. The point is, you should not access the DAL from the UI.

Just like you should not access the database itself from the UI layer, but nothing is going to keep a rogue developer from doing so.

By the way, are you manually creating your composition root? You should probably look at a DI framework. It will isolate a lot of those dependencies, and yes, it needs to know about all the layers, but it keeps those things in one fairly nice and clean place. This guy has a decent rundown of a few of them: https://rules.ssw.com.au/do-you-know-the-best-dependency-injection-container-(aka-do-not-waste-days-evaluating-ioc-containers)

Rob Conklin
  • 8,806
  • 1
  • 19
  • 23
1

You are mixing N-Tier with DI. Both are irrelevant concept and not dependent on each other. For best output, you will need to do deep research for both concept, do several prototype and choose which design is best for you.

That's simply because there is no "correct" or "incorrect" way to implement both concept using those technology stack. There is simply too many way to achieve that.

For example: simple 3-Tier. Consist of DAL (with data models), BLL referencing DAL and Presentation

4-tier. Data model layers, DAL referencing data model, BLL referencing data model, Presentation using Dependency Injection

DDD (domain driven development), which has domain model, database domain model, and presentation layer (additional with CQRS)

Do what you familiar most with. Refactor / rewrite later.

Fendy
  • 4,565
  • 1
  • 20
  • 25
0

This answer to this question in SO gave me the answer or explaination that we were looking for Dependency Injection vs Layered Architecture

Thanks

Community
  • 1
  • 1
sameer
  • 1,635
  • 3
  • 23
  • 35