Hi ppl (basically Oleg and Mark, right?),
As I went by using the T4Toolbox I began to wonder about things...
- How could I write a generator that would write out aspx pages with a simple gridview, for instance, where I could perform CRUD operations on objects? I'm guessing this is possible but
is it worth it? Has it been done already and no one told me? hehehe. I can see this being used in very simple scenarios where one would like to edit the objects, specially during development or early stages in a project.
- What should I do to build a new generator template? Just place the template file in my T4 toolbox templates directory?
- How does the toolbox help me in this task? (point me to some docs please)
I know I'm a little bugger. Sorry about that, guys. But generating code which is really boring to write seems a good idea to me.
Nov 17, 2009 at 11:15 AM
My answer to your first question is "it depends". You could certainly create a generator that creates CRUD screens. It's not a trivial task, you might want ot check out something like
Sharp Architecture, which uses T4 toolbox to generate data access and presentation layers for an application. You could also use
Dynamic Data in ASP.NET to accomplish this.
For answer to your second and third questions, I would suggest going through the tutorial articles listed
>>>How could I write a generator that would write out aspx pages
...you just need to make the templates.
>>>Has it already been done
...I think the answer is "probably" but I do not know where. Do you want to use T4 or something else? There are a lot of code generators out there. It is the thing to do. The question is whether or not to use it to create a UI, I think. See http://www.CodeGeneration.net
and www.CodePlex.com and www.SourceForge.net and etc to find free code generators. Oleg points out 1 of my favorites, Dynamic Data. However, as much as "I want to believe" that generating a UI with a code-generator or dynamically is nice, the promise
is more than the pudding. What happens to me over and over is that I get a UI generator working and then my client says "can you change it to do X" and it turns that the simple change, X, happens to be either unsupported in the generator or it is
simply not possible or it is as difficult as coding by hand. As such, I love the idea, but have not found something that works as I would like it to and I do not want to build it. Etc. That said, Dynamic Data is the best so far, IMHO, but it has some serious
limitations out-of-the-box and requires customization. Much more promising than generating a UI is generating part of a BusinessLayer or DataLayer. That one ought to do, IMHO. That is what I do now, usually. Work towards a well-layered architecture and use
code generation in the BusinessLayer and DataLayer. The UI generation is still hit-or-miss.
>>>What should I do to build a new generator template?
...I like, oddly enough, my sample, which can be found at this link...
...and just look for the latest "Northwind01_T4Sample_*.zip" file and that will show you how one can setup T4 Templates, etc, but it does not generate any UI components.
>>>How does the toolbox help me in this task? (point me to some docs please)
...as Oleg notes, read his tutorials and do them. That is how I got started. Then look at the samples, maybe even my sample.
-- Mark Kamoski