I've built ASP.NET webform projects in the past, and when generating Subsonic classes, the teams I have been on have put our Business Layer/DAL objects into a Project.Framework project.
Would that still be a recommended structure, or should the Subsonic classes go directly into the /Model folder within the MVC web project?
It shouldn't go in the Model folder (I think the Model folder should just be used for a Class that is made only for the view and wont be used in the rest of the app).
It should go into a separate assembly Maybe Project.Core or Project.Data
I would not put the Subsonic classes directly in the MVC project. Since you didn't with ASP.NET, there is no reason to change now.
I wouldn't even leave the Controllers in the MVC web project.
You can put them in Model, and move them to their own project later, but its not really any more work to just put them in their own project now, so I would just do that.
Related
I'm currently learning ASP.Net MVC; I'm using Visual Studio Express 2012 with MVC4 (which is the last version) and I'm totally new to this stuff. My goal is to rewrite a huge web application to MVC, so I was told to separate my main solution into 3 projects using the code-first method:
The core (models and controllers I guess)
The UI (views, scripts, and Content)
And the Database (Entity Framework 5.0 will be used)
I'm quite familiar with MVC, but not separating stuff into different projects. Now I'm a bit lost, I don't have a clue on how to do that, which should reference who, where, how, etc.
Your solution could be structured this way:
UI - ASP.NET MVC application project containing the controllers, views, view models, mapping logic between your domain models and view models, scripts, styles, ...
DAL (EF 5.0, EF autogenerated domain models, Data Contexts, ...) everything that is specific to the data retrieval
The UI layer will then reference the DAL layer.
Some people might also opt to externalize the controllers, view models and mapping logic into a third layer which in turn will reference the DAL layer. The UI layer in this case will reference both other layers.
There are tutorials available on here: http://www.asp.net/mvc
It really helped me out to get the basics of MVC, but be aware - sometimes there are parts missing in the video's, but you can find the code which isn't provided easily elsewhere.
Good luck :)
The tutorials are used to show code first.
create an empty solution using the Visual Studio Blank Solution template
add a solution folder (folder name will be your project name)
then right click that folder and select add project then select "class library" (for The c# classes domain logic)
same again right click the folder and select add project then select asp.net mvc3 template
then same way you create the test template as a new project.
For more information you can follow this book http://www.apress.com/9781430234043
Where do utility methods go in MVC setup? They are not Models, Views or Controller. They don't belong in those folders. So do is the only right thing to do is to keep utility methods outside your ASP.NET MVC project and put them into a project of their own?
It really depends on how big your project is. If it's just a small project with a few utility methods, then what I normally do is put them in a folder called "Infrastructure" inside the MVC project.
The initial setup you get for an MVC project is only really a guide (with some exceptions), and you're free to add folders and put code in them if you want to.
If there's going to be a lot of supporting code, then a separate project might be cleaner and easier in the long run.
I created .NET MVC application and I want to move my models (and then Controllers) to a different project in my solution.
I'm a noob in MVC so I need simple explanation please.
Thank you very much
Add a project to your solution called "YourProject.Models".
Add references to System.Data, System.Data.Linq, System.Data.DataSetExtensions (if you're using Linq to Sql)
Add a reference from your original MVC project to the new "models"project.
Move your model classes from your MVC project to the new project.
Compile and run.
Create a new project with appropriate name and move the models to a new project. It is as simnple as that. Then add a reference to the project you are using. Next step is to Create interfaces and implement those interfaces for code separation. Next use IoC (Inversion of control or dependency injection). I suggest asp.net mvc structure map for Ioc. You can use NuGet tool to do the job for you.
Move your models wherever you want and then update the strongly typed views to match ViewPage<Namespace.For.Your.ModelClass> or maybe change the web.config namespace if you do it that way.
I would like to use a WebSite project instead of a Web Application project for an MVC project.
What is the best way to accomplish this and are there signifigant problems that I might run into?
(as a side note, my reasoning for wanting this is because I have graphic designers who put files into SVN but they don't get added to the "project" and don't show up on deployment or deployment testing. My thought was that switching to a Web Site project might prevent this)
You don't need to do anything special if you are not using CodeBehind files (if you're using them, it'll be more complex but anyway, it's an MVC app. If you're using them, don't!). Just take an MVC Web app project and put all source files (*.cs) under App_Code directory of the Web site. That said, I fail to see any advantage for it.
The application project allows you to use the Models folder to embed classes into. This would then be compiled for that web project. A web site does not provide for this directly. It would require that you use an assembly project to maintain all of your classes. Rather than converting from one project type to another (which I am not sure how you wold go about doing that) you can simply attach an assembly project to your web application and not store any classes in the model folder of your application.
Having said this, you should keep your web project as an application as there usually are view specific classes that are required such as a your view model classes that belong in the web project.
Ok, this is possibly borderline-subjective, but I wonder where one would put a simple class that does something within an ASP.net MVC project? I mean a class like the Base36 De/Encoder, that is neither Model nor Controller. Should this always go into a separate Class Library Assembly, or do such Classes have a place within the MVC Web Application project?
And yes, I know that it probably does not really matter, I'm just possibly a bit over careful to learn a new technology the "right" way from the beginning.
I personally put such classes in some common "utils" assembly. Not only does it avoid junking up your MVC project, but such helper classes often find their way into other projects I work on.
You should still have your separate projects where you include your own libraries, helpers and frameworks. You should still see the ASP.NET MVC project as a web project. You don't have to put all your business logic or web helpers in the Model folder.
You should read the article Jeremy Miller wrote recently about separate assemblies. Using the IoC pattern gets you loose coupling in a way that creating a lot of assemblies cannot.