Jeremy D. Miller -- The Shade Tree Developer

Sponsors

The Lounge

Wicked Cool Jobs

Syndication

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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? 


Posted Wed, Jul 9 2008 4:23 PM by Jeremy D. Miller

[Advertisement]

Comments

Mario A Chavez wrote re: Classes that show up in every project
on Wed, Jul 9 2008 5:00 PM

Jeremy;

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

Thx

Database Management » Blog Archive » Classes that show up in every project wrote Database Management &raquo; Blog Archive &raquo; Classes that show up in every project
on Wed, Jul 9 2008 5:01 PM

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

mendicant wrote re: Classes that show up in every project
on Wed, Jul 9 2008 5:41 PM

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.

Dave Laribee wrote re: Classes that show up in every project
on Wed, Jul 9 2008 9:08 PM

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.

Robert G wrote re: Classes that show up in every project
on Thu, Jul 10 2008 1:23 AM

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.

Torkel wrote re: Classes that show up in every project
on Thu, Jul 10 2008 2:35 AM

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),.

Reflective Perspective - Chris Alcock » The Morning Brew #133 wrote Reflective Perspective - Chris Alcock &raquo; The Morning Brew #133
on Thu, Jul 10 2008 3:30 AM

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

Nat wrote re: Classes that show up in every project
on Thu, Jul 10 2008 7:54 AM

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.

Dew Drop - July 10, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - July 10, 2008 | Alvin Ashcraft's Morning Dew
on Thu, Jul 10 2008 8:09 AM

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

Kent Boogaart wrote re: Classes that show up in every project
on Thu, Jul 10 2008 9:06 AM

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.

Alex de Groot wrote re: Classes that show up in every project
on Thu, Jul 10 2008 9:11 AM

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.

Mike D wrote re: Classes that show up in every project
on Thu, Jul 10 2008 10:28 AM

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.

Mike Hadlow wrote re: Classes that show up in every project
on Thu, Jul 10 2008 10:45 AM

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.

Chris Brandsma wrote re: Classes that show up in every project
on Thu, Jul 10 2008 12:26 PM

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();

}

}

Dan wrote re: Classes that show up in every project
on Thu, Jul 10 2008 1:47 PM

Chris Brandsma,

Why not just use KeyValuePair<TKey, TValue>?

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

vincent wrote re: Classes that show up in every project
on Fri, Jul 11 2008 7:28 AM

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.

Matt Ellis wrote re: Classes that show up in every project
on Fri, Jul 11 2008 9:02 AM

+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

Troy Demonbreun wrote re: Classes that show up in every project
on Fri, Jul 11 2008 11:17 AM

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

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

Jeremy D. Miller wrote re: Classes that show up in every project
on Fri, Jul 11 2008 11:49 AM

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

Troy DeMonbreun wrote re: Classes that show up in every project
on Fri, Jul 11 2008 11:59 AM

Try/catch blocks suck.  

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

Andrei Butnaru's blog wrote Programming links 07.11.2008
on Fri, Jul 11 2008 2:31 PM

Programming links 07.11.2008

Guy wrote re: Classes that show up in every project
on Sun, Jul 13 2008 4:00 PM

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)

on Sun, Jul 13 2008 6:39 PM

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

Useful Links #9 | GrantPalin.com wrote Useful Links #9 | GrantPalin.com
on Sun, Jul 13 2008 6:42 PM

Pingback from  Useful Links #9 | GrantPalin.com

Patrick Smacchia wrote re: Classes that show up in every project
on Mon, Jul 14 2008 4:20 AM

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

» Notable posts wrote &raquo; Notable posts
on Mon, Jul 14 2008 6:08 AM

Pingback from  &raquo; Notable posts

Bil Simser wrote re: Classes that show up in every project
on Mon, Jul 14 2008 9:40 AM

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.

Karl Seguin wrote Announcing the .NET Extension Library
on Mon, Jul 14 2008 8:15 PM

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

Community Blogs wrote Announcing the .NET Extension Library
on Mon, Jul 14 2008 8:57 PM

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

» Announcing the .NET Extension Library wrote &raquo; Announcing the .NET Extension Library
on Tue, Jul 15 2008 4:15 AM

Pingback from  &raquo; Announcing the .NET Extension Library

DotNetKicks.com wrote Classes that show up in every project
on Wed, Jul 16 2008 10:37 AM

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

Colin Jack wrote re: Classes that show up in every project
on Sun, Jul 20 2008 10:51 AM

"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?

Score keeping hockey and DDD « Justin Rudd’s Drivel wrote Score keeping hockey and DDD &laquo; Justin Rudd&#8217;s Drivel
on Sun, Jul 20 2008 9:17 PM

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

Hockey News Aggregator » Score keeping hockey and DDD ?? Justin Rudd???s Drivel wrote Hockey News Aggregator &raquo; Score keeping hockey and DDD ?? Justin Rudd???s Drivel
on Mon, Jul 21 2008 4:19 AM

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

Hockey » DU Beats Michigan 3-2 To Win Snoopy Tourney wrote Hockey &raquo; DU Beats Michigan 3-2 To Win Snoopy Tourney
on Mon, Jul 21 2008 9:18 AM

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

Link-Listing – July 08 « Cav’s Weblog wrote Link-Listing &ndash; July 08 &laquo; Cav&#8217;s Weblog
on Mon, Jul 28 2008 6:54 PM

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

Lipitor side effects. wrote Lipitor vertigo.
on Tue, Aug 26 2008 1:41 AM

Lipitor side effects walking walking. Does grapefriut interfere with lipitor. Lipitor versus pravachol. Lipitor the drug. Lipitor grapefruit. Lipitor.

Buy hydrocodone online. wrote Hydrocodone apap.
on Sun, May 31 2009 10:34 PM

Hydrocodone.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Devlicio.us