views:

265

answers:

2

We're using interfaces to represent entity classes in our domain model. We have concrete implementations of these by virtue of using LinqToSql. We have added a factory method to each LinqToSql class which our service layer uses to instantiate a new entity (note; as opposed to the controller's DataBind attribute doing it).

MonoRail's default DataBinder implementation will ignore properties that are defined as interfaces.

Ideally, we don't want to instantiate our data-layer classes in MonoRail - the whole point of the interfaces is to separate these concerns.

Also, we don't really want to create another set of non-LinqToSql concrete classes whose only job is to translate between layers.

It's the end of a really long day over here; please can someone have mercy and point us at the parts of IDataBinder that we should overload with our own implementations, or hint at other approaches we might attempt? ;-)

+3  A: 

Hi Peter.

You should be looking at IParameterBinder. take a look at a post I've written on the subject

A: 

Hi Peter,

As Ken pointed, your idea could be implemented with a custom IParameterBinder.

A solution would be to use IOC:

  • resolve concrete instance of the form from it's interface
  • then use IDataBinder to bind the instance to the request params

Another one would be using IDictionaryAdapter:

  • generate a dto proxy for your interface
  • then use IDataBinder to bind the dto proxy instance to the request params

NB: second option won't work if interface:

  • is not public (hum)
  • has methods
  • or events
  • or readonly properties
  • or setonly properties

Last, I'm unsure of what is the problem exposing concrete class in controller's signature.

I myself use concrete form in controllers implementing interface defined in application layer services, it allows me to have concerns separated on both side:

  • controller side is Http mapping and first level data validation of the form/command
  • application layer services is business validation and processing of the form/command
smoothdeveloper
At the time, I was committing the sin of binding to my entity classes directly, which happened to be interfaced. I stopped doing that ;-)
Peter Mounce