SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)

    Question MVC Logic Separation Question

    Ok, I am trying to decide on the best way to separate program flow and logic in my mvc app.

    What I'd like to see in my controller actions (in regards to initial viewing) is something like:

    dim cprovider as CategoryProvider = new CategoryProvider
    dim fprovider as ForumProvider = new ForumProvider

    dim cmodels as List(of CategoryModel) = cprovider.getCategories()

    for each c in cmodels
    dim fmodels as List(of ForumModel) = fprovider.getForumsByCategoryID(c.ID)

    for each f in fmodels
    if UserCanViewForum(f.ID) then c.Forums.add(f)
    next

    next

    The question is, should I create a separate logic layer to go in between the controller action and the data providers so that things would read more like:

    Dim logic as IndexLogic = new IndexLogic

    ViewData.Model = logic.getCategoryAndForumListing(CurrentUser.ID)

  2. #2
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Short answer: Yes

    Long answer (while being lazy): http://codebetter.com/blogs/ian_coop...ontroller.aspx

  3. #3
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    I agree, and now I'm wondering what to call these things. I already have the following in my tree/namespaces:

    /Binders
    /Controllers
    /Engines
    /Extenders
    /Models
    /Providers
    /Services
    /Validators

    Plus a few other standard things. I thought about /Commands but they aren't really a single command, but a unit of logic. However, /Logics just doesn't look, or sound, that great (not that it would matter to the compiled app). Do you have any suggestions?

    Note: A few of the folders above have subfolders. For example /Models/Form and /Models/Data. The reason is because the models that represent input collected from a form doesn't always represent a specific record in the database. Therefore, I separated them out into namespaces. I also have divisions under /Controllers for my app Areas and have adjusted my custom ViewEngine class and Views folder to compensate.

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We have three types of services in our application, and are partioned accordinly:

    Project.Domain.Services - Contains our domain level services that work on or with our domain model
    Project.Infrastructure.Services - Services that work on a larger scale or with external resources like files or web servies reside here
    Project.Web.Services - These are essentially the ones you have been discussing


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •