开发者

MVC vs Dependency Injection

Can anyone summarize or bulleted list the types of things that go in each layer, and what layers are there in an MVC type design if you account for Dependency Injection?

I haven't found any clean diagrams that help me figure out where or try to go more in detail without writing an entire book.

I've been doing windows forms apps (including the sql server database design) for 3 years now as my sole function at work , with no one more experienced over me. I have been trying to break things apart into clean layers as much as I can figure my way through on my own based on presentation, business, database.

However based on reading the samples of Dependency Injection in .net it appears that the business logic should be the heart of the application with a separate layer开发者_如何学Go that points to the specific database implementation. So then the ui goes in the presentation layer, controller just provides an abstraction/mapping layer to what the ui is allowed to do in the model layer, the business logic goes in the model layer, and the database/linq-to-sql goes in the database layer. Where everything can depend on the model layer, but it should depend on nothing.

To enable you to move the heart from X type to:

  • Windows forms
  • Asp.net
  • Asp.net MVC
  • Silverlight
  • Anything else

right? Would a 4 layer/project approach cover this type of thing? I suppose it would be 5 if you add a TDD layer.

I'm not averse to reading books, but I have plenty to read ( 3 at home, 1 at work, 3 ordered, 1 for college) already that are quite thick. Both of these approaches have resounding supporters but seem to conflict on overall design.

  • Extreme programming
  • windows forms in action
  • The productive programmer(75% done)
  • User interface design for programmers (90% done)
  • Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries (2nd Edition) - at work that I got from code camp
  • The Art of Unit Testing - The Art of Unit Testing with Examples in .NET Roy Osherove
  • Operating systems concepts with java - for a master's in computer science class
  • C# in depth(not release yet)
  • Functional Programming for the real world(not released yet)


I think you're trying to understand too much at one time. For instance, a "TDD layer" makes no sense. DI and MVC are only tangentially related. DI does not specify what layer the business logic should be in.

Start simple. Work on one concept at a time. Test out your knowledge in one language before trying to apply it everywhere. You've got some great books on your reading list; work through some of them. The Art of Unit Testing will give you a basic understanding of TDD; it covers pragmatic uses of Dependency Injection as well, but doesn't go very deeply into it. The Extreme Programming series will cover TDD in more detail.

I'd suggest reading up on design patterns (don't start with the Gang of Four book - maybe Head First Design Patterns) and general design principles (Clean Code is a good start). Perhaps others can suggest references for learning about layered architecture.

Expect this to take a while. Expect to continue learning throughout your career.


I think this link will cover most of your questions: http://wiki.sharparchitecture.net/SettingUpNorthwind.ashx

It's not possible to compare MVC vs dependency injection.

Dependency injection is often used in MVC to make the controller and the view independent of how the data is persisted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜