Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

c# - ASP.NET MVC (Domain Model, Repository, Fluent, Services - Structure for my Project)

In my ASP.NET MVC web application, I have:

  • Domain Model, created by LINQ to SQL

  • Repositories such as

    UserRepository and OrderRepository

  • IQueryable Fluents as IQueryable Extension Methods such as

    public IQueryable<Order> GetNewOrders(this IQueryable<Order>)

  • Services such as

    UserService and OrderService

  • Utility Classes and Extension Methods such as

    CryptoUtility (doing Hashing etc.) and String etc. extensions

  • ViewModels which are special for each MVC View

  • The ASP.NET MVC project itself (Controllers, Views)

I'm looking for the best project structure/organization for my case, especially separating into different assemblies and how dependencies should look like between these layers. Web resources unfortunately don't go into good detail about this.

One hint: Currently Repository, Services, IQueryable Fluents etc. work directly against domain model implementation, I don't have an interface definition for them. I considered it unnecessary but maybe this is needed for loose coupling? My Services have an interface (e.g. IOrderService), and my repositories implement IRepository<T>.

Appreciate your input on organizing this in a concise manner, and especially what layer should depend on what & assembly organization. Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would look at the article by Jeffrey Palermo on the Onion Architecture here. This basic architecture works well in any project and will allow you to separate your core project (domain layer, persistence, etc.) from your web project.

We use this with MVC/StructureMap/FluentNHibernate and have had great success.

We end up having a structure similar to the one below.

> trunk
  + build (build scripts)
  + lib (external libraries)
  > src (source code)    
   >> Organization.App (solution name)
     >> Organization.App.Core (code library)
        + Config
        > Domain
          > Model
          > Persistence
          > Queries
          > Services
        > Persistence
        > Services
     >> Organization.App.Web (mvc web app)
        > Assets
          + Images
          + Scripts
          + Stylesheets
        + Controllers
        + Views
        + ViewModels

That's the basic idea. The web app references the core app for domain entities our repository/unit of work. Check out this older project on google code for a similar example. The great part about this is we have been able to add new "UI" project types to the same solution and re-use our core project as intended. Like a console app or a second web app, or whatever you need.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...