Sunday, June 07, 2009

T4 Templates

Recently been investigating T4 templates. Been doing a lot of work using TDD, with the assistance of Rhino Mocks which is great, but in order to embrace SOLID principles, in particular the Single Responsibility Principle and the Interface Segregation principle I’ve found a lot of coding repetition.

Working with Linq, it takes a responsible attitude towards design to allow proper unit testing. This can be mitigated using technologies such as Type Mock but when tools such as this are not available, you need to ensure you design for testability rather than use tools to provide testability.

To this end I’ve been working with Fowler’s Table Data Gateway pattern, to separate out the actual data access from any business logic associated with it. This leads to a lot of gateway code in itself, DTO code and access code up at the provider level. This provides great testability, working with IoC but does require quite a lot of boilerplate code.

To this end, I want to use T4 Templates to automate some of this work, allowing testability and to maintain adherence to the aforementioned principles.

So, started learning by looking at the following:

Linq To SQL Code Generate with T4

Advanced code generation patterns with T4 and DSL tools

Text Template Transformation Toolkit

I’ll post back here my experiences in using T4 to tackle this issue.

0 comments: