3

I use the repository pattern for data handling.

In my DAL folder i have IUserRepository, UserRepository and UserContext. Inside the models folder i have a class called User like id, username etc.

I read on the internet that I should do as less as possible in the controller. What do they mean?

I want to determine where to put the business logic For example I want to page a login page. What would happen if I put the login function alongside the models?

using IndividueleOpdracht.Dal;

namespace IndividueleOpdracht.Models
{
    public class AccountModel
    {
        public void Login(string username, string password)
        {
            // Do something with the repositories?
        }
    }
}

And then just call the AccountModel.Login method in the controller?

2
  • 2
    You need to spend more time with Fowler first, before you ask questions like this here. Nov 28, 2015 at 20:02
  • I made this question more objective by asking "what" instead of "why," and wonder if it can be re-opened in its current form.
    – Tom Au
    Nov 29, 2015 at 15:07

1 Answer 1

3

I read on the internet that I should do as less as possible in the controller. What do they mean?

They mean the Controller is a part of the UI. And you should do only UI-related things inside it. If you need to so something with your model data, you place those actions into another layer (bussiness layer, logic layer, call it whatever you like) and call that layer from the controller.

I want to determine where to put the business logic For example I want to page a login page. What would happen if I put the login function alongside the models?

You need to follow SRP when determining where to put things. Login does not look to me like a method of the user model itself. More like it belongs to authorization / authentication module of your business layer. But you decide of course.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.