Tim McCarthy's Blog

Stuff I think about...

My Links

Blog Stats

News

Archives

Post Categories

Image Galleries

Tuesday, November 27, 2007 #

My 11/27/2007 San Diego .NET User Group Presentation

Here are the slides and here is the code from my presentation yesterday.  A big thank you to everyone who attended, I thoroughly I enjoyed discussing DDD with you guys!

By the way, here is the link to my book on the Wiley web site:

http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470147563.html

posted @ 10:27 PM

Wednesday, November 07, 2007 #

My 11/6/2007 .NET Developers Group Presentation

Here are the slides and here is the code from my presentation yesterday.  Thanks to everyone who attended, I thoroughly I enjoyed discussing my upcoming book with you guys!

By the way, here is the link to my book on the Wiley web site:

http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470147563.html

 

posted @ 12:50 PM

Tuesday, October 16, 2007 #

Slides and Code from my ITARC 2007 Presentation

Here are the slides and here is the code from my presentation today.  Once again, a big thank you to all who attended, you were all very helpful to me!

As I said before my book should be out in April of 2008…it sure is a lot of work doing a book all by myself  :)

posted @ 9:25 PM

Friday, April 27, 2007 #

Issue #1: What data type to use for my domain object keys

In my book, one of the first issues that I am running into is trying to determine what data type to use for the domain object keys in my application.  I am using a SQL Server database, and I am not sure if I will be using guids or integer keys yet, so I think I will just use a data type of System.Object (a la Rocky’s CSLA).

Later on I might refactor this into a Key [Fowler PoEAA p 224] class if I need to.

I am putting this Key property in my domain model’s Layer Supertype class.

posted @ 9:36 PM

Thursday, April 26, 2007 #

The source code for my book's case study application now has a home

I now have a CodePlex project set up for the case study code for the book.  I love CodePlex, it is the great TFS in the sky!

Here is the link to my CodePlex project:

http://www.codeplex.com/dddpds

posted @ 5:34 PM

Friday, April 20, 2007 #

Code and Slides from my 4/19/2007 IASA SoCal presentation

This was for my talk titled “Domain-Driven Design using the ADO.NET Entity Framework.”  First of all, a big thank you to Mike Vincent for allowing me to speak at this great group, and also a big thank you to Woody Pewitt for being a great host and friend.

As promised, here are the slides and code from the presentation.  I also need to send a thank you out to Mike Pizzo for answering all of my Entity Framework questions…Thanks Mike!

Like I promised in the presentation, for my DDD book I am going to use the Entity Framework from my repositories, even though there is a lot of pain right now without the designer not being available and the lack of persistence ignorance in the EF.  I really believe in this technology and the team developing it, and I know they will eventually succeed in getting a product out there that us DDD’ers will like and use.

posted @ 12:15 AM

Tuesday, March 06, 2007 #

I am writing a book on Domain-Driven Design

I have been talking to people about this for a while, so I figured I’d blog about it too.  Actually, I promised my friends over at the Domain-Driven Design Yahoo group that I would!  The full title of the book is .NET Domain-Driven Design with C#: Problem-Design-Solution, and it will be published by Wiley Publishing, Inc.

The idea behind the book is that it will be a case-study book…a real-world application that uses Domain-Driven Design (DDD) concepts.  After reading other bloggers’ posts, and hearing people ask for real-world examples on the DDD Yahoo group, I have decided to write a book that addresses this exact topic.  The book is due to be completed at the end of the year, and will probably be out in early 2008.

My plan is to put some of the issues I run into on this blog and/or the DDD Yahoo group and see what other people have to say about their solutions to similar problems.

posted @ 11:07 PM

Friday, March 02, 2007 #

Code and slides from my Enterprise Library 3.0 Webcast today

Thank you everyone for attending!  Sorry I forgot to do the ASP.NET validation demo, but it’s in the code in the List.aspx page of the sample application.  Oh yeah, and here is the link to David Hayden’s excellent tutorials on Enterprise Library 3.0.

As promised, here is the code and here are my slides.

posted @ 2:29 PM

Wednesday, February 14, 2007 #

My talk on Static Code Analysis for the Southern California .NET Developers Group

First of all, I’d like to say thank you to the group for having me speak at the meeting last night.  The audience was very knowledgeable and asked great questions!

Here are the slides for the presentation (sorry about the dark fonts).  To get the code, I suggest reading this post, which contains the code and explanation for the code.

posted @ 10:07 AM

Tuesday, February 13, 2007 #

How to Create Custom Code Analysis Rules for VSTS 2005

Building New Rules

The first step is to make sure there is not an already existing rule that is doing what you are trying to do!

 

Use the IK.CodeAnalysis.Rules solution to add new classes to the IK.CodeAnalysis.Rules project inside of the solution.  Each new class will correspond to a new rule.

 

Add a new rule element to the Rules.xml file.  Follow the examples from the rules that are already there. 

 

 

 

Figure 1.1  Rules.xml file

 

All new classes must inherit from the BaseRule class.  Make sure to add a private static class called “Constants” in the new Rule class.  This is where the name of your rule as well as its resolution name will go.  See the example rule classes in the project for reference.

 

Make sure that the Resolution element’s Name attribute is what you reference in the new Rule class as well as the Rule element’s TypeName attribute.  These values should correspond to what both of the values are in the RuleName and ResolutionName constants in the private static Constants class of the new Rule.  Feel free to put any other string literals into the Constants class.

 

 

Figure 1.2  The Constants class

 

Next, figure out what scope the new rule applies to; it may apply at several levels, such as Field, Property, Parameter, Method, etc.  For whatever levels your rule applies, override the appropriate Visit methods from the BaseIntrospectionRule class.

The “Visit” Methods

The BaseRule class extends the BaseIntrospectionRule class, which in turn extends the StandardVisitor class.  There are over 140 Visit methods that the StandardVisitor class calls during a rule check operation.  What this means is that any Visit methods that are implemented in the new Rule class will be called by the rule framework.  This is great because it allows rule developers to only focus on the parts of an assembly’s IL that they care about, such as all methods, or all private fields, etc.  In order to trigger an error or warning to appear from a rule that has been broken, a call must be made to the BaseRule.AddProblem method.

 

In Figure 1.3, a call to AddProblem is made when a private field has been flagged as having a prefix in front of it.

 

 

Figure 1.3  An example of overriding the VisitField method

Debugging Rules

Follow the instructions outlined in #13 of the Resources section.  In the IK.CodeAnalysis.Rules solution, there is a file named CommandLine.txt which contains a sample command line for debugging the custom rules in the solution.  There is also an FxCop project file in the solution, fxcoptest.fxcop, which is necessary for debugging.  In order to get debugging working, the rule developer will need to modify the paths referenced in both of these files to point to the correct locations on their machine.  Once everything has been modified correctly, copy and paste the text from the CommandLine.txt file into a command-prompt window, and then run it.

Deploying Rules

In order to deploy the IK rules, the IK.CodeAnalysis.Rules.dll assembly file must be copied to the C:\Program Files\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\Rules directory on each machine where the rules are to be run.  That’s it, Visual Studio will load up and process all of the assemblies in this directory.

Suppressing Rules

There are some cases where it will be necessary to allow a rule violation in your code.  A typical example might be a rule violation that is more of a design suggestion, instead of an actual violation, such as having a “GetXYZ” method that returns a certain type.  This will result in a rule violation stating that the method be changed to a property, but you may have a very good reason to keep it as a method.  In those types of cases the rules can be suppressed, but should be suppressed in code using the System.Diagnostics.CodeAnalysis.SuppressMessageAttribute attribute.  Here is an example of what this looks like in code:

 

 

Figure 1.4 Suppressing a Rule

 

More information about this attribute can be found here.

 

Resources:

The very first resource any new rule developer should look at is #6 (Writing Custom FxCop Rules by Guy Smith-Ferrier) in the list below.  This is a pdf version of a PowerPoint presentation that explains the process of building rules very well.

 

1.  http://blogs.msdn.com/fxcop/archive/2006/11/16/faq-how-do-i-share-managed-code-analysis-rule-settings-over-multiple-projects-david-kean.aspx

 

2.  http://blogs.msdn.com/fxcop/

 

3.   http://www.gotdotnet.com/community/usersamples/default.aspx?ProductDropDownList=FxCop&SortDirection=Desc&SortColumnName=CreationDate

 

4.  http://www.gotdotnet.com/team/fxcop/

 

5.  http://blogs.msdn.com/fxcop/archive/2007/01/22/faq-what-exception-should-i-throw-instead-of-the-reserved-exceptions-found-by-donotraisereservedexceptiontypes.aspx

 

6.  http://www.guysmithferrier.com/downloads/FxCop.pdf

 

7.  http://davidkean.net/archive/2004/08/09/145.aspx

 

8.  http://msdn.microsoft.com/msdnmag/issues/04/06/Bugslayer/

 

9.  http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1090172&SiteID=1

 

10.  http://davidkean.net/articles/BaseRule.aspx

 

11.  http://www.codeproject.com/cs/algorithms/Not_Used_Analysis.asp?df=100&forumid=332089&exp=0&select=1783417

 

12.  http://dotnetjunkies.com/WebLog/tim.weaver/archive/2005/01/12/43651.aspx

 

13.  http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1090172&SiteID=1

posted @ 1:38 PM