How are you using CodeSmith with CSLA

How are you using CodeSmith with CSLA

Old forum URL: forums.lhotka.net/forums/t/1760.aspx


wjcomeaux posted on Tuesday, November 14, 2006

How are you guys primarily using CodeSmith? Are you generating your business objects and stored procedures on a onezee basis? Meaning, you identify that you need an EditableRoot from your User table so you open CodeSmith and simply generate an object from the table and then tweak where necessary? Or have you set up a large ORM file that specifies what objects you want to generate from what tables? Some other method?

How about complex BOs that join multiple tables. Did you write custom templates for sprocs and BOs or are you just coding these by hand?

Also, how do you handle cases where a generated file has been edited outside of the code generator. It doesn't appear that CodeSmith tracks this for you inerently, unless it is an option I am missing.

So, how are you using it?

Will

cds replied on Tuesday, November 14, 2006

Hi Will

Good questions! I think code generation is the "holy grail" of CSLA.

The CodeSmith templates are a good start, but I think most everybody will need to modify them in some way to make use of them.

I recently built a prototype of a system using those templates as the basis of my BOs. I used the XML (CslaXml) template and put all my definitions in a big XML document. But it's not documented, and the sample doesn't really cover everything you need, so it does take some reading of the templates and the underlying TemplateBase.cs file to understand how to make use of them.

Those templates, however, do allow for generation of partial classes. So I would treat the generated code as not modifiable - and make your changes to the user partial classes. That way, you can regenerate the classes at any time (which you'll want to do when things change, like DB fields etc.)

In the end though I've found that the CodeSmith templates are a good starting point, but I've now moved on to my own solution - I'm actually using LLBLGenPro as my data access technology, so the existing CodeSmith templates weren't that helpful as they assume using stored procs to access the DB.

LLBLGen is basically a code generator itself, so I've written CSLA templates for that, and I've built my own LLBLGen designer plug in for designing my BOs using the LLBLGenPro database meta-data to help out my code generation and also my BO design experience. Basically, from within the LLBLGen designer, I hit the F7 key and it generates all my data access classes and my CSLA business object classes according to the way I've designed them from my use cases.

I'm really pleased with the result, and it has lots of nice features - for example, I put all my BOs for each use case in a separate namespace (and separate folder in my library project) so it keeps things nice and organised. I also name the generated files as xxx.Designer.cs which works beautifully in VS - you get your user classes and the generated class in a tree, just like VS does with forms, etc.

Anyway, I'm not sure what I'm going to do with my design tool. It's obviously LLBLGen specific, but I think that it has huge potential value. I'm currently using it to build a relatively complex system, and it really is working out very productively. Perhaps one day I'll think about releasing it so that others can use it.

Craig

Copyright (c) Marimer LLC