I have the following real world scenario, somewhat simplified for the sake of this example
I have an object, let's call it Movie which will consist of several attributes, such as
I need to be able to have a form where a new movie can be entered, with the following elements on the form:
What would be a clear consice way to organise my code using asp.net mvc, please outline where
So far I have
But I am unclear how does the actors/genres arrays fit into this and where do I fetch the data for it....does it go into IMovieRepository interface? Do I create another interface for it, in other words do I create an interface for a ViewModel? Do I create an interface for fetching genres too? Another question: How do I use ViewModels? Do I need to change anything in the application settings?
Controller action has something like View() in their body....how do I pass ViewModel there? Do I need to?
All in all, I just want a simple example of how you would implement the scenario above.
I am new to MVC and trying to make sure my code is organized well.
I remember very good word from Mike Cohn about Agile,"Best Practice Is Not Exist"
So you should always keep improving and refactoring not only for your code but also for your design, architecture, methodology, etc. and to do this You will need the following:
I know it a bit long introduction, but it necessary to understand me why I will advise you doing my approach as the following
My default approach in MVC project as the following
But as I told you, Best Practice is Not Exist so I will start my development using BDD and TDD, and to implement this I founder and create a framework "DevMagicFake" that published on CodePlex, this framework will enable me to finish and complete my view and make it real working without any design or code for the underline layers at all
After the feature is working with all unit tests that cover most of it's behaviors, I will start refactoring the whole
and for each refactor I run all needed unit tests to find-out if my refactor break my code or breaking the accepted and knowing behaviors of the application, if it happen I will fix any break
So for example to save a Customer and retrieve it I will use only one line of code in each action method like the following
public ActionResult List(CustomerVeiwModel customerVeiwModel)
{
var repository = new FakeRepository<CustomerVeiwModel >();
repository.Save(customerVeiwModel);
And to retrieve the customer I just need to code the following:
var repository = new FakeRepository<CustomerVeiwModel>();
var customer = repository.GetById(1);
So I always take the decisions of the ViewModel, Repository, Architecture, etc, after 2 points
This will make me aware of what to do about design, develop architecture and make me confidence that my code really work with high quality and as the customer expected
At the end, There is just one word, I always keep refactor and refactor, every new feature, modification, problem or issue happen to me it may lead to new architecture concept or design decisions that will change the whole application and I am always ready for them.
by the way you can download MVC3 project that use my approach form DevMagicFake on CodePlex, you will find project called "TryFakeMVC3"