My DSL experience

A couple of days ago my recent pull request for FubuMVC has been accepted- a feature I’ve been working on that allows registering through conventions the partial view that would be used for a certain partial model. This meant writing some DSL which was a first time for me.

In case anyone stumbles upon this entry and wants to find out more about what is DSL and how to do it properly, I will recommend you to head straight towards Jeremy D. Miller’s thorough article on the subject.

My target was simply to allow the developer to write

 types.For<MyPartialModel>().Use<MyPartialView>();

In order to do that I added the following:

  1. IPartialViewTypeRegistry
  2. IPartialViewTypeBindingExpression
  3. IPartialViewTypeRegistrationExpression

The registry would register each partial model type to its partial view type, the latter being a page (implementing IFubuPage). At first I had my registry containing also the For method which passed the partial model type and returned a binding expression which contains only the Use method so that the user could only tell the registry to use the view for the model (so that the Use method was ‘void’).

Afterwards I added the registration expression in order to hide the registry interface. The registration expression contains only the For<TPartialModel>() method.
Inside the FubuRegistry I added then the following method:

public void RegisterPartials(Action<IPartialViewTypeRegistrationExpression> registration)
 {
 var expression = new PartialViewTypeRegistrationExpression(_partialViewTypes);
 registration(expression);
}

That way, the IPartialViewTypeRegistry instance (the _partialViewTypes field) is completely hidden.

Advertisements
Explore posts in the same categories: Fubu

Tags: ,

You can comment below, or link to this permanent URL from your own site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: