There is a similar question already asked by someone BUT it was related to ASP.NET MVC and not Web API. I have some common code which I want to execute in every action in Web API certain controllers. What is a good way for such situation?
ASP.Net Web API and ASP.Net Wep MVC has the same core. Also you can use the same answer describe in your link :
creating a BaseController and inherit all your controllers
creating an ActionFilter like here
I have tried to understand the MVC3 framework and when I used to start on a Project I Don't know that where I am starting the project what the arrangement of files And Why I am Adding Controllers Models As I am a Beginner somebody Please guide Me about its Structure of Solution Files and folder where we have To start If Want something To make In this framework so What should I do For this.
MVC is a software architecture - the structure of the system - that separates domain/application/business (whatever you prefer) logic from the rest of the user interface. It does this by separating the application into three parts: the model, the view, and the controller.
Check this ASP.NET MVC Overview .. It may clear you all doubt that what is Model , View and Controllers etc. First you learn about the MVC architechture, then look for the project.
spend few mintues learning these Model-View-Controller, What is MVC, really?, Wiki - MVC. It may help you to know about MVC project structure and interaction related stuff..
follow the Microsoft tutorial step by step.. There is much good tutorial named MVC Music Store
The best ASP.NET MVC tutorial I know is the NerdDinner application contained in "Professional ASP.NET MVC 3". It has been created by Scott Hanselman and is in production use online at http://www.NerdDinner.com.
Free ASP.NET MVC eBook Tutorial , Microsoft MVC Book or Tutorial Recommendation
Check recommended books for MVC 3. I like Pro ASP.NET MVC 3 Framework by Steven Sanderson.
https://stackoverflow.com/questions/6315616/best-book-on-asp-net-mvc-3
When using MVC framework, where should I place general purpose classes that aren't necessarily deserving of a model?
I would Say:
If classes are pertaining to app e.g. login validation put it under app/libraries.
If classes are pertaining to MVC e.g. session class put it under /libraries
/ being your DocumentRoot.
BTW I am writing an MVC for a project of mine. Which is ~90% complete.
It is good to keep the files as segregated as possible (by experience).
Here is the directory structure of Obullo MVC:
Codeigniter which is an MVC framework would have you put them in a libraries file. This is outside and independent of the MVC triad.
does anyone have good links or tips on best practices concerning migrating from ASP.NET Webforms to ASP.NET MVC?
We have a large webforms application that we would like to piece by piece migrate to MVC. Here is our current setup.
Two big Webforms project (VB)
Multiple class libraries and services (C# and VB.Net)
Subsonic 2.2 Data access layer
SQL Server 2008 DB
We are considering the following:
Keep the classic webforms project running as is for now while developing.
Create new MVC project based on MVC 3 with Razor view engine
Use Nhibernate (Repository pattern) DAL
Convert/build the existing functionality module by module in the MVC project
Replace some functionality in the old webforms project with new MVC modules if possible. Integrate via eg. Iframes.
In time the new MVC app will replace the old webforms project entirely.
We would like to keep the DB as is so we also need a tool to create the Model based on the DB.
Is this a possible solution?
WebForms applications use server-side session a lot because most of the server controls use it internally. You will not be able to use any of the server controls that you used in WebForms in MVC3 (atleast without some tinkering).
MVC3 promotes the use of restful architecture, where any state is maintained in html or url or cookies, and these are reasons why I think you should revisit the decision to convert to MVC3. Do so only if it will give you a huge advantage, because I suspect you will be reinventing ground up your existing app - I suspect there will be an equal amount of effort migrating it as to while developing it new.
Again there is nothing preventing you from creating an "area" or a "region" of MVC in your webforms app, if your goal is to use MVC for future development.
If you still want to move to MVC3, take a look here
It is ok solution. Also for NHibernate you can use MyGeneration with NH plugin to generate models on top of existing DB. And it is also possible to host WebForms and MVC together in one web app. Just finished quite the same task. But used EF for DAL.
I know that an MVC framework allows you to separate business logic, data base access and presentation, but why do we need a framework to do this.
Can't we just keep our classes separated, perhaps using different packages/folders for the model, view and controller classes?
In my opinion the thing you are talking about is the MVC pattern and not a specific framework. Of course you can go and keep all your classes within one project and still use the MVC pattern, as you have all your UI code in the views, the logic in the controllers, ...
A MVC framework on the other hand makes it easier for you to use this pattern. It may provide some base classes for controllers and a mechanism for the communication between view and controller.
I don't know if you are familiar with ASP.NET MVC. The framework itself is very small, but it helps you developing an application with the MVC pattern, as you don't have do think about the previously decribed areas...
Hope this helps
An MVC framework is a framework written to split up the the business logic, database access and presentation.
This is very useful in most web applications, and now lately into software/desktop applications.
This is due to the fact that following the MVC model, your code will be much clearer, cleaner and you keep your application DRY (Do not Repeat Yourself).
You can write your own classes and separate them into Model, View and Control. But again, you will need a framework to help you in accomplishing certain tasks. Like a List control in ASP.NET, or PHP framework being able to help you translate text between languages and so on. (Oh why reinvent the wheel?!)
MVC and framework is a different thing. MVC is just an architectural pattern, which can be applied with any project, with or without framework.
So you don't need a framework to do this. You can separate them by yourself. :)
MVC stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner than the traditional ASP.NET web development. Web applications developed with ASP.NET MVC are even more SEO (Search Engine) friendly.
Developing ASP.NET MVC application requires Microsoft .NET Framework 3.5 or higher.
Model:
MVC model is basically a C# or VB.NET class.
A model is accessible by both controller and view.
A model can be used to
pass data from Controller to view.
A view can use model to display
data in page.
View:
View is an ASPX page without having a code behind file.
All page specific HTML generation and formatting can be done inside view.
One can use Inline code (server tags ) to develop dynamic pages.
A request to view (ASPX page) can be made only from a controller’s action method
Controller:
Controller is basically a C# or VB.NET class which inherits system.mvc.controller.
Controller is a heart of the entire MVC architecture.
Inside Controller’s class action methods can be implemented which are responsible for responding to browser OR calling views.
Controller can access and use model class to pass data to views
Controller uses ViewData to pass any data to view.
MVC is a code organization architecture style to organize your code-logic in a meaningful way for web applications. As a programmer I have almost puked when I have inherited other people's code when their code logic is all over the place and following their web application code turns into following a rabbit down the gutter hole. Why MVC? hmm.. well why should I use a filing cabinet or folders to organize my plethora of paper and not just have my papers stashed in a large pile and have others figure how they connect to each other. It increases code readability. With MVC it becomes very easy to follow code logic since you are following standard structure for a web application. Business logic is separated out from UI. Easier to delegate work decouple work on a project.
You can of course approach it yourself by segregating your classes. A framework supplies common scaffolding that you wouldn't have to build yourself. But it will also impose some structure on your code. You'll have to evaluate whether the framework helps more than it hurts.
You are correct, there are strategies that you can implement to help with separation of concerns without using MVC.
Microsoft's ASP.NET MVC framework is one strategy that can be employed, and that is what I think you are asking about.
This MVC framework makes such separation of concerns easy.
The other major advantage of MVC is testability - (depends on whether you believe in unit testing - I do).
The MVC framework ensures that all orchestration logic is on your controllers and through the FormControls collection allows full unit testing of all aspects of your application except for how it is presented.
As the MS MVC framework encourages adherence to common rules and structure of the application which should lead to greater maintainability.
The major downside of MVC is the code-in-front code weaving required for presentation, but this can be easily overcome.
Perhaps this is just a linguistic thing. I've seen "frameworks" referring to themselves as a DSL -- Domain Specific Language.
And you don't need a framework But here's something to consider: You already know for a web app you're going to want to do a few common things... route URLs, render pages, etc. Why re-write it all? For other problem domains you'll have generic things to do as well.
Hai Friends There are somemany types of architecture frame work has been there,firstly i know 2tier and 3 tier frame work ,the 3 tier and mvc ,entity framework are same but in different name's,so study a good background in any one architecture there fore if you went to any multinational companies ,you can easly score/highlight to your carrer.
Model View Controller or MVC as it is popularly called, is a software design
pattern for developing web applications. A Model View Controller pattern is made
up of the following three parts:
**Model** - The lowest level of the pattern which is responsible for maintaining data.
**View** - This is responsible for displaying all or a portion of the data to the user.
**Controller** - Software Code that controls the interactions between the Model and View