CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeremy D. Miller -- The Shade Tree Developer

Under the hood and working with .Net, TDD, Software Design, and Agile Stuff

Classes that show up in every project

Just out of whimsy, here's my list of classes or interfaces that seem to show up in every project I work on.  

  1. Bootstrapper - sets up StructureMap and whatever UI machinery.  I formalized this in StructureMap 2.5 for diagnostic purposes.
  2. Debugging - Just a test fixture marked as explicit for playing with little bits of code and troubleshooting
  3. ObjectMother and/or DataMother (Test Data Builder ala Nat Pryce)
  4. TestUtility - Usually just a quickie way to run Fit/StoryTeller tests inside of NUnit tests
  5. ICommand - Execute() and usually something else
  6. A console app called DatabaseGenerator to setup the development and testing databases.  Wraps the NHibernate hbm2ddl tool for us.
  7. A console app called CodeGen to kick off whatever code generation we're using.  We codegen DTO's and Fit Fixture classes.
  8. If it's a desktop application, I'll have an ApplicationController and ApplicationShell
  9. SpecificationExtensions - This is relatively new.  I love the SpecUnit stuff that Bellware did with extension methods for RSpec like unit test assertions.  We add our own extensions at will.
  10. XmlExtensions - Extension methods for Xml manipulation.  Just a little bit of effort makes Xml consumption so much easier
  11. IRepository.  We dumped IRepository<T> with Save(T) methods in favor of IRepository with Save<T>(T) and use Linq for NHibernate to express queries to avoid having to write one off repositories for each aggregate root.  It's too early to say if it's a better approach, but I'm hopeful.  Our current one looks like:

    public interface IRepository

    {

        T Find<T>(long id) where T : Entity;

        void Delete<T>(T target);

        T[] Query<T>(Expression<System.Func<T, bool>> where);

        T FindBy<T, U>(Expression<System.Func<T, U>> expression, U search) where T : class;

        T FindBy<T>(Expression<System.Func<T, bool>> where);

        void Save<T>(T target);

    }

 

 

What's yours?  Or is this just a sign of being in a rut? 



Comments

Mario A Chavez said:

Jeremy;

Will be great is you can post the code of some of those classes

Thx

# July 9, 2008 5:00 PM

Database Management » Blog Archive » Classes that show up in every project said:

Pingback from  Database Management  &raquo; Blog Archive   &raquo; Classes that show up in every project

# July 9, 2008 5:01 PM

mendicant said:

One that comes to mind for me is some sort of an ILogger (we've got a bunch of legacy apps with their own 'logging' system) so we've ended up putting in a facade that takes whatever format that particular app's Logging facility looks like and maps it to log4net.

# July 9, 2008 5:41 PM

Dave Laribee said:

I'd also like to put in a request to talk about how you're using Linq/NHibernate and maybe functional-style programming with your single repository.

# July 9, 2008 9:08 PM

Robert G said:

Log (sometimes replaced by Log4Net)

Utilities (everything miscallaneous)

BusinessBase - business base class.  I've inherited a couple of CSLA.NET based projects, which has a similar, if not overcomplicated business base classes.

DataBase - my tried and true database access base class - sometimes replaced by something shiny like Subsonic or NHibernate or CodeSmith generated magic

Here is my typical solution, broken down by projects

PresentationLayer

BusinessLayer

CommonLayer

DataLayer

Yeah, it might be a sign of a rut.

# July 10, 2008 1:23 AM

Torkel said:

I usually have a static IoC class that wraps Castle Windsor, a helper class named Db for bypassing nhibernate and using ADO.NET directly for ex. Db.Transaction(delegate(IDbCommand cmd) {})

If it's a WebService app I usually have a EntityTranslator service which translates domain objects to DTO (and back),.

# July 10, 2008 2:35 AM

Reflective Perspective - Chris Alcock » The Morning Brew #133 said:

Pingback from  Reflective Perspective - Chris Alcock  &raquo; The Morning Brew #133

# July 10, 2008 3:30 AM

Nat said:

I always end up writing a clock interface.  Something like (in Java):

 public interface Clock {

     Instant now();

     Date today();

 }

Then having a SystemClock that delegates to the static time APIs, and a StoppedClock for fixing the time in unit tests.

# July 10, 2008 7:54 AM

Dew Drop - July 10, 2008 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop - July 10, 2008 | Alvin Ashcraft's Morning Dew

# July 10, 2008 8:09 AM

Kent Boogaart said:

I always have some kind of abstraction over logging (whether I'm using log4net, System.Diagnostics or whatever) to do stuff like log performance in code blocks and log an exception easily.

And - not really a class - but I always end up with a Build project, which contains any MSBuild tasks needed to support the build. And it also contains post-build steps for full builds, like running unit tests and FxCop etcetera.

# July 10, 2008 9:06 AM

Alex de Groot said:

I think your approach is the start of your own software factory. You're not already identifying a lot of abstract steps you take before you start developing. The next step is to become more concrete and combine this stuff in predefined templates, etc.

# July 10, 2008 9:11 AM

Mike D said:

Similar to your IRepository solution we added a Save() Extension method to IQueryable and the implementation wraps the datacontext / session.

We then grab IQueryable<T> from the IoC container.

Still early, but time will tell.

# July 10, 2008 10:28 AM

Mike Hadlow said:

My IRepository looks very similar but instead of

T[] Query<T>(..)

T FindBy<T, U>(...) and

T FindBy<T>(...)

I just have a single

IQueryable<T> GetAll<T>()

In my unit tests I have mock repository builder methods that return mock repositories that spew out lists of test data whenever GetAll() is called. Any Linq extension methods that I chain after GetAll() then simply work on that object graph rather than being translated into SQL.

It's nice to wrap up specific queries in extension methods, then you can write stuff like:

var orders = orderRepository.GetAll().ThatMatch(criteria);

or maybe

var orders = orderRepository.GetAll().ThatHaveNotBeenBilled();

Like you I'm still experimenting with this pattern.

# July 10, 2008 10:45 AM

Chris Brandsma said:

a generic name value class.

public class NameValue<TName, TValue>

{

public TName Name { get; set;}

public TValue Value { get; set; }

public override string ToString()

{

return Name.ToString();

}

}

# July 10, 2008 12:26 PM

Dan said:

Chris Brandsma,

Why not just use KeyValuePair<TKey, TValue>?

msdn.microsoft.com/.../8e2wb99w.aspx

# July 10, 2008 1:47 PM

vincent said:

Good idea to list those. For me, it comes down to about this:

DataProvider

Logging

Settings (or Config or whatever)

APPNAMEContext (like WebshopContext, or CommunityContext)

Utils

Events

MessagingEngine

Thinks like that.

# July 11, 2008 7:28 AM

Matt Ellis said:

+1 for the linq/nhibernate.

I'm a bit of a newbie with nhibernate, and realise it's a different mindset to the traditional DB way I've been working previously. I've understood nhibernate to be a persistence layer to enable you to work in terms of a domain model, rather than in terms of your database model. In other words, to get at data, you navigate rather than query. And so it follows that having to perform a query is an indication that there's something missing in your domain model.

Assuming I've got the general idea, why do are you querying the database? What kind of data are you getting back?

Cheers

Matt

# July 11, 2008 9:02 AM

Troy Demonbreun said:

Source code for Jeremy's IRepository & Repository classes are available here:

storyteller.tigris.org/.../IRepository.cs

# July 11, 2008 11:17 AM

Jeremy D. Miller said:

PROVISO:  The source code is available, but it's a naive implementation at the moment.  Note the total absence of adequate try/catch blocks.

# July 11, 2008 11:49 AM

Troy DeMonbreun said:

Try/catch blocks suck.  

Maybe we could start a new "Exception Ignorance" grassroots movement.

# July 11, 2008 11:59 AM

Andrei Butnaru's blog said:

Programming links 07.11.2008

# July 11, 2008 2:31 PM

Guy said:

1) ICommand

2) IRule<T> with the bool FulfiledBy(T candidate) method

3) A Guard class for parameter validation.

4) On.UIThread<T>(Func<T> operation)

5) ApplicationShell

6) EventBroker of some sort with the Subscribe and Publish methods

7) EventHelper for raising events(hate repeating that eventName != null crap)

# July 13, 2008 4:00 PM

Design, Solutions and .NET Framework said:

Quick overview on few interesting posts in the previous days: The very useful CR_Documentor 2.0 has been

# July 13, 2008 6:39 PM

Useful Links #9 | GrantPalin.com said:

Pingback from  Useful Links #9 | GrantPalin.com

# July 13, 2008 6:42 PM

Patrick Smacchia said:

Path handling library,

considering that a path is a string is such a poor practice with all the path richness (file/folder, absolute/relative, operation...)

www.codeplex.com/FileDirectoryPath

# July 14, 2008 4:20 AM

» Notable posts said:

Pingback from  &raquo; Notable posts

# July 14, 2008 6:08 AM

Bil Simser said:

Stuff we have that at some poinit will get harvested into a framework:

* DependencyResolver. This is our wrapper for any IoC (used to be called IoC). Has methods like Initialize (which takes in something to use to resolve, like an IWindsorContainer) and Get<T> to get a dependency

* IBuilder Fluent fixture for building entities. Like ObjectMother but a little more flexible

* ISpecification<T> A generic for creating specification objects to filter out items from entitiy collections. Have a few blog posts on this that I need to get out

* IValidationStrategy<T> A strategy pattern implementation on creating various validations for entities. An example like ReadOnlyValidation would be used in the UI to set controls to non-editable. Keeps validation out of the domain and into a service object.

# July 14, 2008 9:40 AM

Karl Seguin said:

285 days ago I blogged about my dislike for extension methods. Extension methods aren&#39;t very discoverable

# July 14, 2008 8:15 PM

Community Blogs said:

285 days ago I blogged about my dislike for extension methods. Extension methods aren&#39;t very discoverable

# July 14, 2008 8:57 PM

» Announcing the .NET Extension Library said:

Pingback from  &raquo; Announcing the .NET Extension Library

# July 15, 2008 4:15 AM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# July 16, 2008 10:37 AM

Colin Jack said:

"Keeps validation out of the domain and into a service object."

Do you mean that you aim to move all validation out of the domain, or just that you try to keep GUI focussed validation out?

# July 20, 2008 10:51 AM

Score keeping hockey and DDD « Justin Rudd’s Drivel said:

Pingback from  Score keeping hockey and DDD &laquo; Justin Rudd&#8217;s Drivel

# July 20, 2008 9:17 PM

Hockey News Aggregator » Score keeping hockey and DDD ?? Justin Rudd???s Drivel said:

Pingback from  Hockey News Aggregator &raquo; Score keeping hockey and DDD ?? Justin Rudd???s Drivel

# July 21, 2008 4:19 AM

Hockey » DU Beats Michigan 3-2 To Win Snoopy Tourney said:

Pingback from  Hockey &raquo; DU Beats Michigan 3-2 To Win Snoopy Tourney

# July 21, 2008 9:18 AM

Link-Listing – July 08 « Cav’s Weblog said:

Pingback from  Link-Listing &ndash; July 08 &laquo; Cav&#8217;s Weblog

# July 28, 2008 6:54 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Jeremy D. Miller

Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy previously worked as a systems architect building mission critical supply chain software for a Fortune 100 company and learned agile development practices as a .Net consultant at ThoughtWorks, one of the pioneers of agile development. Jeremy is the author of the open source StructureMap (http://structuremap.sourceforge.net) tool for Dependency Injection with .Net and the forthcoming StoryTeller (http://storyteller.tigris.org) tool for supercharged FIT testing in .Net. Jeremy's thoughts on just about everything software related can be found on his weblog "The Shade Tree Developer" at http://codebetter.com/blogs/jeremy.miller, part of the popular CodeBetter site. Jeremy is a Microsoft MVP for C#. Check out Devlicio.us!

Our Sponsors

Free Tech Publications

This Blog

Syndication

News

All opinions expressed here constitute my (Jeremy D. Miller's) personal opinion, and do not necessarily represent the opinion of any other organization or person, including (but not limited to) my fellow employees, my employer, its clients or their agents.

About Me

"Best Of" Compendium

StructureMap (Dependency Injection for .Net)

StoryTeller (Supercharged Fit)

Build your own Cab

TestDriven

MVP