I recently completed an MVC3 project for a client using a Repository pattern implemented using a micro ORM, and with a service layer for my business logic. IMHO the application works well and the client is happy.
But I had to write a lot of boilerplate code whenever I wanted to add/implement a new service and associated DTO's. Plus there was a fair amount of code duplication converting DTO's to View Models and back again, with associated PEBKAC. And as the requirements evolved there were changes to the database schema that needed to be propagated right through to the View Models.
For a different client I inherited a .netTiers code generation project that caused me a lot of grief until I fixed some defects in the base templates, automated the code generation using MSBuild and, also using MSBuild, massaged the resulting code to get it to build without the catalog of manual tweaks previously required. .netTiers ultimately generated a lot of useful code but with enormous amounts of duplication, a bucket of complexity, and it felt like using a sledgehammer to skin a cat.
Now I'm looking at another MVC3 project and I want to avoid having to write all the boilerplate myself but I also want to avoid a full .netTiers-type code generation. I haven't used EF. I've tended to think of it as too big a tool for the size of projects I undertake but if it can take away some of the manual steps for me then that would be a big time saving. What are the merits of EF and will it scaffold the service layers for me?
The other option I'm considering is LightSpeed which would require me to spend some dollars (not many) but if it can generate service layer code for me that would be money well spent. Does LightSpeed support this type of code generation?
Obviously as the domain model and database schema evolve the services need to be updated to accommodate those changes. .netTiers implements this by generating partial classes. How do these other tools handle those changes without overwriting any custom logic in the service layer?
What other options are there?
Update: Thanks for all the feedback, lots of positive options to look at. Has anyone had a look at MVC Scaffolding?
Update #2: I'm going to pursue the MVCScaffolding option which produces code for EF Code First. Out of the box it produces a Repository class and then somewhat unfortunately sticks it with the Model which in MVC is actually the View Model and not the Domain Model. There is a pull request on the MVCScaffolding project for Service layer scaffolding so will investigate that option. Plus AutoMapper for mapping POCOs <-> DTOs.
T4 templates work very well and are easily modifiable. They can be used for the datatier layer as well as any service layers.
The process we use for EF Code Only:
The new tools in Entity Framework are great as they give you various options:
A beta release of Code First Migrations has been released. We haven't investigated it yet but it looks interesting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With