Automating Development in ASP.NET MVC
Basically I am thinking of automating the whole process of creating Repository classes (including required entries for properties and fields), Model classes, Service layer (layer where you put your business logic) interfaces and classes and maybe even Controllers and Views! Wouldn’t this be real good treat if all of this code writing could be automated!! Unless you have already seen this automation implemented by someone somewhere elsewhere, I am sure you are excited by this idea.
Well, I do all my projects in MVC pattern implementing Entity Framework and Unit of Work Pattern for Data Layer and Service Layer. Basically, I keep a project for Data Access Layer where the .edmx file generated by EF stays along with repositories for each Database objects. Then I expose the repositories for each Entities by a central repository using a Unit of Work pattern.
Then I keep another project for Model classes. For every entities generated by EF, I have models in this project.
Then I have third project for Service (or Business Logic) Layer where I have interfaces and their implementations to do all CRUD activities.
Finally for displaying the View to the user, I use a ASP.NET MVC project where I have controllers for each Entities. These controllers receive request from views and process data as per the request using the Interface exposed by Service Layer. The response sent from controllers to View is usually in JSON format.
The big realization is that no matter what type of entities we are dealing with the whole process of creating Repositories, Models, Services, Controllers and even the Views stays the same. The only changes that we will find are in the Members (Properties) of our Entities.
If we are dealing with User entity, we will have properties like Username, Password and Email and if we are dealing with Product entity, we will have properties like ProductName, ProductPrice, Category and so on.
Hence, if we just replace the properties and entity names, everything stays the same. This opens up the possibility for automating this whole process like I mentioned in the beginning of the post. Heck if I am able to automate only 70% of the process and make necessary adjustments for the remaining 30%, I would be more than happy.
I will be giving this a try and will write about it once its done. What are your thoughts on this?