0

Let's have an oject structure like this :

Company -> Department -> Person

-> means 1:M relation

Should I have one fat controller which serves all request for this objects or one controller per every object ?

There will be the usual CRUD operations for each object. The details (Department,Person) will be displayed on one page using grids.

5 Answers 5

2

If its like an admin type thing, I would just use a single controller or use dynamic data. Otherwise I like to breakdown my controllers based on behavior for example, Room Booking, Time-sheet management etc.

Sign up to request clarification or add additional context in comments.

Comments

2

Following DDD - if only Company is aggregate root - then one (but still thin) controller

Comments

1

I don't think there is a direct relationship between your data model and your controllers. I view controllers as groupings of related functionality, from the prespective of the application. What I mean is that I typically create a controller for each big logical chunck of functionality. So if I were creating a contacts MVC web app, I might have:

  • AccountController (for authentication/authorization)
  • ContactsController (for the real business case, contacts)
  • AdminController (for super users to modify the app)

By in my data model I might have tables like, User, Contact, Address, Phone, etc.

Comments

1

I would have a separate controller for each. If one controller (like company) has to pull people information that is fine.

If you really want Render Action. This lets you view call into another controller to load that part of the view.

Comments

1

I usually go with one controller per object per CRUD ... so one controller for Department and one for Person. Why?

You should either have a DTO or Repository for each. If you have a repository:

public class PersonController : Controller
{
    private IPersonRepository _personRepository;
    public PersonController(IPersonRepository personRepository)
    {
        _personRepository = personRepository;
    }
}

Then use an IoC container (I like StructureMap) for the dependencies.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.