Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC general class location

In the MVC folder structure, where should general class files reside? For example, I have a class that determines the right DataContext to use, so I'm not reinventing the wheel in each of my controllers. Should it live in the Controllers folder even though it's not a controller? Should it be with the Models because it's database related, even though it's not a model? Possibly the Views\Shared folder? Or is Content the catch-all folder for that kind of stuff? I'm sure I could put it anywhere, but I was wondering where the "right" place is.

like image 914
gfrizzle Avatar asked Feb 03 '09 15:02

gfrizzle


2 Answers

It's not a controller, content or a view, so don't use those. It sounds most closely related to your model, so you could put it in model under a subfolder called "Helpers" or "Utility" or some such. Or you can add another top level folder called Services and put it there. That's where I put all my app logic, the middle man between the controllers and the model.

like image 78
John Sheehan Avatar answered Oct 24 '22 01:10

John Sheehan


If you look at Rob's MVC Storefront: Separate class library project (like Commerce.MVC.Data)

like image 3
dmajkic Avatar answered Oct 23 '22 23:10

dmajkic