MVC

Scaffold Your ASP.NET MVC Web App For Rapid CRUD Functionality

September 6th, 2012 0 Comments

The term “Scaffolding” is used by many software technologies to mean “quickly generating a basic outline of your software that you can then edit and customise”. The scaffolding package we’re creating for ASP.NET MVC is greatly beneficial in several scenarios:

  • If you’re learning ASP.NET MVC for the first time, because it gives you a fast way to get some useful, working code, that you can then edit and adapt according to your needs. It saves you from the trauma of looking at a blank page and having no idea where to start!
  • If you know ASP.NET MVC well and are now exploring some new add-on technology such as an object-relational mapper, a view engine, a testing library, etc., because the creator of that technology may have also created a scaffolding package for it.
  • If your work involves repeatedly creating similar classes or files of some sort, because you can create custom scaffolders that output test fixtures, deployment scripts, or whatever else you need. Everyone on your team can use your custom scaffolders, too.

Other features in MvcScaffolding include:

  • Support for C# and VB projects
  • Support for the Razor and ASPX view engines
  • Supports scaffolding into ASP.NET MVC areas and using custom view layouts/masters
  • You can easily customize the output by editing T4 templates
  • You can add entirely new scaffolders using custom PowerShell logic and custom T4 templates. These (and any custom parameters you’ve given them) automatically appear in the console tab-completion list.
  • You can get NuGet packages containing additional scaffolders for different technologies (e.g., there’s a proof-of-concept one for LINQ to SQL now) and mix and match them together

 

Installation:

You can install the package using the NuGet Package Manager Console, so it only takes a few seconds and you don’t have to download anything using your browser.  To do so,

  • Open the Package Manager Console window using Visual Studio’s View->Other Windows->Package Manager Console menu item.
  • Enter the following:
Install-Package MvcScaffolding

 

Create Model:

Add the following class to your Models folder, then compile your solution (Ctrl-Shift-B):

namespace MvcApplication1.Models
{
    public class Test
    {
        public int TestId { get; set; }
        public string Name { get; set; }
        public string City { get; set; }
        public DateTime Founded { get; set; }
    }
}

 

Let The Magic Begin!

Create a complete Create-Read-Update-Delete (CRUD) UI for this model by issuing a single scaffolding command into the Package Manager Console:

Scaffold Controller Team

 

Notice that it’s created everything you needed, including the controller and all of the logic required for the CRUD functionality, and the associated views.  It will include form validation as well.  It’s all there and ready to go.  Does it get any easier?

 

Top 10 Reasons Why CodeIgniter Rocks

July 13th, 2010 1 Comments

CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks, CI might be for you.

10. MVC Architecture
The model, view, controller architecture is nothing new. It seems like all the coding frameworks are MVC nowadays, and if they aren’t it can be configured easily. I have had experience building large apps the procedural way and every time they end up with unmanageable spaghetti code. The MVC way of doing things offers nice code separation and keeps things clean. Some frameworks force you to do things by the books but CI lets you use MVC in a way that makes sense you. If that means ignoring models all together then so be it.

9. Little to no server requirements.
Unlike other PHP frameworks, CI works with both PHP 4 and 5. That makes the lives of someone like me who has to be able to work seamlessly between the two environments much easier. Of course I have painted myself into a corner from time and used PHP5 techniques in my apps, but the framework itself works on either.

8. Easy to understand and extend.
CI is the first framework that I used that actually makes sense to me. I have tried Cake PHP, the Zend framework, Symfony and many others and I was able to get up and running with CI the quickest. CI is also easy to write new libraries, change the behaviour of existing libraries and just change the overall behaviour of the framework with little effort.

7. All the tools you need in one little package.
Calendar, e-mail, zip encoding, validation, uploading, sessions, unit testing… that is just a few of the built in libraries that come with CI. It also includes a boat load of default helpers for things like forms, file handling, arrays, strings, cookies, directories and more. Plus, if that wasn’t enough, you can create your own libraries and helpers or use code that has been developed by the CI community and posted to the wiki.

6. No “installation” necessary.
Believe it or not, one of the hardest things I have experienced with trying new frameworks is installing them. I am not a fan of UNIX command line so I tend to look for tools that I can install and use by just uploading files to a directory. CI fits this requirement nicely. No need for PEAR packages or server modifications to get the framework up and running. Just upload the files to your server and your off.

5. Built in security tools.
CI allows you to implement as much or as little security as you feel is necessary for your app. It does some things by default like unsetting all global variables regardless of PHPs register_globals directive and turning off the magic_quotes_runtime directive during system initialization so that you don’t have to remove slashes when retrieving data from your database. Other things can be enabled like cookie encryption, handling session data with a database and automatically escaping SQL queries.

4. Database abstraction and more.
Every decent framework has a database abstraction layer nowadays and CI is no exception. You can easily create insert, update and delete statements without needing to write raw SQL. Handle connections to multiple databases within one application and connect to any of the following database types: MySQL (4.1+), MySQLi, MS SQL, Postgre, Oracle, SQLite, or ODBC. CI also lets you manipulate your database like add/remove columns from tables, create new tables and remove old ones using it’s new database forge library.

3. Large and active user community.
The last time I checked, there were over 57,000 registered members on the CI forums. That is a nice and big user community to work with when you have a problem or question. The CI website has a forum and wiki when your looking for answers. No confusing group mailing lists or chat channels just to get a quick answer to a question.

2. Excellent documentation.
By far, the biggest advantage of CI over any other framework is it’s documentation. I will admit to trying some other frameworks while they were still in BETA and under development. But, CIs documentation is 10 times better than other framework documentation I have come across and I strongly think thats because CI is backed by a company and not just a community. EllisLab, the company behind CI, takes a lot of pride in CI and they have big plans for it and thats why they don’t have a problem in spending the time that is necessary to come up with quality documentation for the user community.

1. One in the same with ExpressionEngine.
The #1 reason why CI rocks is that ExpressiongEngine, EllisLabs content management system, is currently being built on the framework. This means that whatever libraries, helpers, etc. that you develop for CI you can use with EE in the future and vice versa. This also means that whatever EE needs to operate, CI gets. This could means things like an improved parser class, built in user authentication, ability to easily program modular applications and more.

If you like to development using an OO framework… there’s no better place to start then CodeIgniter.