Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid having to write boilerplate code?

Well, I've been following the NerdDinner tutorial online and I've completed it to a T.

Now I've implemented a project of my own using pretty much the same architecture.

I notice my process is:

  1. Create database.
  2. Create DBML.
  3. Create |TableName|Repository.cs class with data access methods.
  4. Create partial |TableName| class to handle validation.
  5. Rinse and repeat for all tables.

By the time I'm done I'm exhausted and I haven't really done anything except drag and copypaste code and change variable names.

What am I missing here. Where can I improve this boilerplate haze I'm in?

Edit: Sans creating my own T4 template, is there a tool that will help me?

like image 521
Sergio Tapia Avatar asked Jul 28 '10 22:07

Sergio Tapia


Video Answer


3 Answers

See Visual Studio Templates.

I haven't used them, but I assume if you take the time to customize them, you'll be able to make Visual Studio generate a lot of what you already do instantly specifically using the T4 template language/interpreter thats embedded in Visual Studio.

like image 190
Omar Avatar answered Oct 06 '22 00:10

Omar


I haven't used it much but perhaps you could create a codesmith template to handle this. http://www.codesmithtools.com/

I have seen it used to good effect with Nettiers and in some other scenarios.

like image 40
Dean Johnston Avatar answered Oct 06 '22 01:10

Dean Johnston


Have a look at this for ideas. It uses a generic repository and the unit of work pattern.

http://elegantcode.com/2009/12/15/entity-framework-ef4-generic-repository-and-unit-of-work-prototype/

Also here.

Advantage of creating a generic repository vs. specific repository for each object?

I've implemented something based on these ideas. You may also want to look at using a service layer more interfaces etc than the nerd dinner example shows.

As good as the tutorial is, it isn't IMO really fit for use in an enterprise application as it is still quite tightly coupled.

Hope this helps.

like image 22
davy Avatar answered Oct 06 '22 00:10

davy