Skip to content
Lars-Erik Aabech edited this page Oct 20, 2013 · 8 revisions

Why

There's currently a DynamicContent instance available in Umbraco, so you can actually write CurrentPage.SomeProperty to get a document value in your view. However, for starters, it doesn't give you any intellitip in Visual Studio, and if it doesn't exist it won't show as an error with ReSharper for instance.

Further, it is nearly impossible to unit-test dynamic content from Umbraco, not to speak of extending them with business logic.

So we're left with the option of wrapping IPublishedContent with static types. These have to be written manually, and you have to plumb a bit to make it the Model of your MVC Views, or accessible in WebForms.

Some times when fleshing out a project, it's also nice, if not completely necessary to start by writing unit-tests and actual code. Wouldn't it be nice if the document types just "magically" appeared when you're done? This is known as a "code-first" approach.

This is where this project comes in...

How

Umbraco CodeGen is dependent on another Umbraco package called USync. It imports and exports all Umbraco metadata (everything but content) to XML on disk. Using this XML, we're able to generate code, and by parsing code, we're able to generate XML back.

When Umbraco starts, CodeGen will parse code you've pointed to and generate XML for document types and media types. USync will then diligently import this XML to Umbraco. Whenever a content type is changed, USync will write it to disk as XML, and CodeGen will grab that XML and generate a class for each type.

Depending on whether you'd like to "code-first" or just get some nice strongly typed models for your types, you'll [configure] USync and CodeGen differently.

Detailed instructions

  1. Installing
  2. Configuration
  3. Writing classes
  4. Customizing
Clone this wiki locally