2

I wonder if project structure and naming convention which I use in ASP.NET MVC and Web API projects are ok. These technologies are quite new to me, so I don't have my own standards yet.

I don't change default convention in controllers and views. I change Models directory name to ViewModels. Every View has it's own ViewModel, if it's needed. I don't use entity sets as view models. In Infrastructure folder I put DI classes and HTML helpers.

Short example:

DAL
    Abstract
        IUnitOfWork.cs
        IGenericRepository.cs
    Concrete
        UnitOfWork.cs    
        GenericRepository.cs
        AppContext.cs
        AppUserManager.cs
        AppRoleManager.cs
    Entities
        AppUser.cs
        Other.cs    
ViewModels
    Users
        ListViewModel.cs
        CreateViewModel.cs
        EditViewModel.cs
        ChangePasswordViewModel.cs
    Account
        LoginViewModel.cs

When I use Identity, I don't create repository for users, but in every controller class which needs it I have UserManager and RoleManager private property.

I don't know how to separate MVC and Web API controllers when I use both technologies in one project. For example when MVC sends view to the client and the rest is loaded dynamically using Web API. Is it good idea to put them in different folders?

Controllers
    MVC
        UsersController.cs
    WebAPI
        UsersController.cs
  • 1
    Maybe naming folders in DAL subfolders can be grouped by business perspective. This can help if you need separate product in modules. – Pagotti Nov 23 '16 at 16:06
3

ASP.NET MVC and Web API don't have a convention that constraints the controllers to being placed in a specific folder within the project structure. That being said, you can place them all in the same folder, if you like. Having them in separate folders is good since, and you've given a good example, you can have conflicting names.

I would separate the DAL folder into several projects, mostly for reusability purposes. But that's just my preference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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