The most daunting task when trying out or learning a new framework or technology is figuring out where the heck to start. Take S#arp Architecture for instance (arguably, the world's most insanely amazing framework ever written by mankind...more or less). As incredibly cool as S#arp is, it can be intimidating trying to figure out where to start. To make that first step a bit easier, the following will get you up and running with your first S#arp project in about 15 minutes or less. (Steps verified on WinXP Pro.)
Here's what you'll have in less than 15 minutes:
- A new S#arp Architecture project generated using a VS template,
- CRUD pages for managing product categories for our crazy cool store,
- live communications with the application database,
- and unit tests verifying that everything is working.
Download S#arp Architecture and Generate Your Project
- Download and unzip the latest release at http://cloud.github.com/downloads/codai/Sharp-Architecture/SharpArchitecture_1.0_2009_Q3.zip. We'll call the unzip location <ROOT>.
- Close all running instances of VS 2008.
- Install <ROOT>\tools\T4 Toolbox 188.8.131.52.msi. (You'll need to uninstall any existing version before doing so (not compatible with latest T4 Toolbox...yet.)
- Install <ROOT>\tools\NUnit-184.108.40.20622.msi. (It's likely compatible with later versions of NUnit as well.)
- Copy <ROOT>\VisualStudioTemplate\SharpArchApplicationTemplate.zip to "C:\Documents and Settings\<YOUR USERNAME>\My Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual C#\Web" (You'll need to create the \Web folder. Also, be sure to copy the zip, don't unzip it!)
- Copy <ROOT>\VisualStudioTemplate\SharpArchApplicationWizard.dll to "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE"
- Open VS 2008 and select File / New Project / Visual C# / Web / S#arp Architecture Application. For the name, enter "MyCoolStore" (no spaces!), set the location to whatever you'd like (e.g., "C:\MyStuff\Projects\"), and keep "Create directory for solution" unchecked. Then click OK. (It'll take about a minute to generate the solution...when the status changes back to "Ready" in the very bottom left of VS, you're good to go.)
- Build the solution (should build without a problem).
Hook Up to a Database
- Run NUnit and select File / Open Project, to then open <ROOT>/MyCoolStore/tests/MyCoolStore.Tests/bin/Debug/MyCoolStore.Tests.dll
- Run the tests and see the Data tests fail due to a DB connection timeout. Time to create the database!
- Create a new SQL Server database called MyCoolStore. (Other DBs are supported.)
- In VS 2008, open MyCoolStore.Web/NHibernate.config and modify the following bits in the DB connection string: YOUR_SERVER, YOUR_USERNAME and YOUR_PASSWORD. Save the file.
- In NUnit, run the tests to see all the tests pass...if all is green, your project is talking to the database. (If the tests under Data still fail, recheck your DB connection string.)
- In VS 2008, right click the MyCoolStore.Web project and "Set as Startup Project" and click F5 after doing so to run the project. (Not much to see here yet beyond the landing page...let's add some CRUD functionality.)
Generate CRUD Scaffolding
- After verifying that the web project is running, stop the debugger.
- In VS 2008, open Code Generation/CrudScaffolding/ScaffoldingGeneratorCommand.tt and do the following:
- Change line 19 to:
- Delete the four additions to entityScaffoldingDetails, lines 25-36, and replace them with:
new EntityProperty("Name", "string",
"Seafood", "[NotNull, NotEmpty]", true)
- Uncomment the 2nd to last line (i.e., remove the "//" in front of
generator.Run()) and save the file...
- The CRUD scaffolding generator will run for a few seconds...it'll be done when the cursor no longer looks like an hour glass. (Yes, that's annoying that it runs when the file is saved...that's T4.)
- Recomment out the 2nd to last line (i.e., add the "//" in front of
generator.Run() back in) and save the file. (This avoids premature generation - always embarrassing - when editing this file in the future.)
- In VS, rebuild the solution.
- In NUnit, run all of the tests...only CanConfirmDatabaseMatchesMappings should fail. Time to add the ProductCategories table!
Create the Database Table
- In NUnit, run just Tests/MyCoolStore/Data/NHibernateMaps/MappingIntegrationTests/CanGenerateDatabaseSchema (which should pass), and change the NUnit tab to "Text Output."
- Copy all of the SQL that you see on the Text Output tab in NUnit and run it against the MyCoolStore database using SQL Management Studio.
- In NUnit, run all of the tests again to see them pass.
- In VS, click F5 to run the project and change the URL, after it loads, to http://localhost:<DEBUG PORT>/ProductCategories. You can now CRUD product categories to your heart's content!
Enforce Object Uniqueness
- Let's say you now want to enforce name uniqueness...
Wanna learn more? Go to http://wiki.sharparchitecture.net/
And for all you S#arp junkies out there...the next quarterly release is coming soon...and it's going to have proper utilization of the application services layer during CRUD generation!
02-01-2010 4:11 PM