Your First S#arp Project in 15 Minutes

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.

Ready?

Download S#arp Architecture and Generate Your Project

  1. 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>.
  2. Close all running instances of VS 2008.
  3. Install <ROOT>\tools\T4 Toolbox 9.5.20.1.msi.  (You'll need to uninstall any existing version before doing so (not compatible with latest T4 Toolbox...yet.)
  4. Install <ROOT>\tools\NUnit-2.5.2.9222.msi.  (It's likely compatible with later versions of NUnit as well.)
  5. 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!)
  6. Copy <ROOT>\VisualStudioTemplate\SharpArchApplicationWizard.dll to "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE"
  7. 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.)
  8. Build the solution (should build without a problem).

Hook Up to a Database

  1. Run NUnit and select File / Open Project, to then open <ROOT>/MyCoolStore/tests/MyCoolStore.Tests/bin/Debug/MyCoolStore.Tests.dll
  2. Run the tests and see the Data tests fail due to a DB connection timeout.  Time to create the database!
  3. Create a new SQL Server database called MyCoolStore.  (Other DBs are supported.)
  4. 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.
  5. 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.)
  6. 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

  1. After verifying that the web project is running, stop the debugger.
  2. In VS 2008, open Code Generation/CrudScaffolding/ScaffoldingGeneratorCommand.tt and do the following:
    • Change line 19 to:
      new EntityScaffoldingDetails("ProductCategory");
    • Delete the four additions to entityScaffoldingDetails, lines 25-36, and replace them with:
      entityScaffoldingDetails.EntityProperties.Add(
         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.)
  3. In VS, rebuild the solution.
  4. In NUnit, run all of the tests...only CanConfirmDatabaseMatchesMappings should fail.  Time to add the ProductCategories table!

Create the Database Table

  1. In NUnit, run just Tests/MyCoolStore/Data/NHibernateMaps/MappingIntegrationTests/CanGenerateDatabaseSchema (which should pass), and change the NUnit tab to "Text Output."
  2. 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.
  3. In NUnit, run all of the tests again to see them pass.
  4. 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

  1. Let's say you now want to enforce name uniqueness...
    • In VS, open MyCoolStore.Core/ProductCategory.cs and add an attribute as:
      [HasUniqueDomainSignature(
         Message="Provide a unique name dag nabbit!")]
      public class ProductCategory : Entity
      {
         ...
    • Build the solution, F5 into debug mode, and try to add two product categories with the same name...go ahead, try it, I triple dog dare you.

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!

Billy McCafferty


Posted 02-01-2010 4:11 PM by Billy McCafferty
Filed under:

[Advertisement]

Comments

Rob Reynolds wrote re: Your First S#arp Project in 15 Minutes
on 02-02-2010 7:14 AM

Bill - you ought to set up a warmup for S#arp so we can see it in action in less steps. devlicio.us/.../warmup-getting-started.aspx

Rob Reynolds wrote re: Your First S#arp Project in 15 Minutes
on 02-02-2010 7:21 AM

Let me rephrase so I don't sound rude (if I did): It would be really cool to see a Warmup template for S#arp if possible!

DaRage wrote re: Your First S#arp Project in 15 Minutes
on 02-02-2010 9:18 AM

or "Your First S#arp Project in only 23 steps!"

uberVU - social comments wrote Social comments and analytics for this post
on 02-02-2010 9:34 AM

This post was mentioned on Twitter by devlicious: New Blog Post Your First S#arp Project in 15 Minutes: The most daunting task when trying out or learning a new fra... http://bit.ly/bjeX1c

Billy McCafferty wrote re: Your First S#arp Project in 15 Minutes
on 02-03-2010 4:04 PM

Thanks for the suggestion Rob...I'll take a closer look at that.

@DaRage, :P

June Hu wrote re: Your First S#arp Project in 15 Minutes
on 02-04-2010 9:39 AM

Billy, I have been looking forward to the next quarterly release. Do you have a day yet? Thanks for all the great work!

Billy McCafferty wrote re: Your First S#arp Project in 15 Minutes
on 02-04-2010 12:13 PM

I'm hoping by Feb. 12...but no guarentees. ;)

June Hu wrote re: Your First S#arp Project in 15 Minutes
on 02-17-2010 4:39 PM

I am watching your blog for the next quarterly release announcement like a hawk...

June wrote re: Your First S#arp Project in 15 Minutes
on 02-22-2010 2:53 PM

Hi Billy, I know you must have tons of other commitments to fulfill, but is the next quarterly release on this week's horizon? Time goes by very slowly while waiting... :) Thanks a lot!

Billy McCafferty wrote re: Your First S#arp Project in 15 Minutes
on 04-14-2010 4:15 PM

It's coming out as soon as Alec gets back from his honeymoon next week. ;)

amruta14 wrote re: Your First S#arp Project in 15 Minutes
on 09-24-2010 7:13 AM

Currently I am working on Sharp Architecture 1.6.

Sharp Architecture has two projects CrudScaffolding and CrudScaffoldingForEnterpriseApp for code generation.

What’s the difference between these two projects?

Tony wrote re: Your First S#arp Project in 15 Minutes
on 05-17-2011 10:45 AM

This is really great, only one issue I am seeing is that HasUniqueDomainSignature causes NHProf to bark at you that the use of unbound transactions is discouraged.  Any Idea how to get around that?

Billy McCafferty wrote re: Your First S#arp Project in 15 Minutes
on 05-17-2011 11:37 AM

Hi Tony,

Not sure what to recommend.  You may want to bring it up within the S#arp forums at groups.google.com/.../sharp-architecture

Another thought would be to modify the HasUniqueDomainSignature code so that it looks for an already open transaction, and uses it if available.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)