Model with IMessageReporter?

Sep 1, 2009 at 8:43 PM


I like the approach with the Messages-Collection to present errors to the user. I'm wondering why (I understand, that I'm free to use it differently) the marker interface is set only for a controller and a facade. My understanding is, that the business logic would happen in the model and the controller should be very light. I think that in Catharsis it is assumed that the business logic will find happen normally in the facade or entity. Is this correct?

Kind regards



Sep 2, 2009 at 6:40 AM

Hi Benno.

Firstly: Great that you dive so deep. Tremendous.

Secondly: In a few weeks there'll be new release, which will be more simple, powerful and all current browsers compatible. I wish you to take current as the start up version. The next will help you more in a quick development with powerful separation of concern.

Finally: Messages are thought to be your easy and reliable way of handling incorrect behavior. In fact there are two different layers with different incorrectness handling:

- Controller - this is the UI marshal. That means that controller is responsible for correct binding of the user-sent information (filled Form, QueryString parameters). Controller must convert the strings (parameters' values) into the properties of any entity (BindModel(object)). Also must be able to understand the navigation, asked by user (which action to redirect based on provided data).

-- Controller incorrectness: the Messages collection comes to play, when any error (intended or misunderstand ) appear (incorrect date, int, decimal format etc.) If any unauthorized action is requested...

- Business - this layer is independent on the UI (MVC layers). This core piece of your application is responsible for Business logic. Can be item deleted? Can be stored entity with provided properties (missing one, longer or shorter one). Provide the list based on search criteria (filtering, paging and ordering) (this is done on Data layer physically, but from the business point of view - the only gateway for whole application is the Facade - independent on data storage type) (By the way, next release will provide amazing proof of concept - Data layer based not on DB but on XML!!!)

-- Business - incorrectness comes from the entity unintended states (but type is correct - e.g. date is date, but lower then the rules can allow) . User tries to delete entity which is used somewhere;does not provide the string value (which can be null by .NET but only Empty by business rules) etc.

And for both these parts there is really easy and powerful way of handling: Messages collection. Whenever on any of these two layers an error is appended, whole framework will grant you:

1) user is informed 2) Changes won't bubble into data layer


The essence of the IMessageReporter comes from the Messages.Add() operation:

If there would be

  "Messages.AddError(object reporter, string shortName, string messageTemplate, params object[] arguments)"

Then the call inside controller's action:

  "Messages.AddError(this, "formatFailure", "The date '{0}' was not recognized", date); "

will be OK as well the call with forgotten 'this' parameter:

  "Messages.AddError("formatFailure", "The date '{0}' was not recognized", date); "

Because the string is object as well.

The IMessagesReporter is only marking interface. And you are 100% right that you can mark any other object with it, to allow acting as IMessageReporter. We very often append new libraries for batch importing, batch exporting etc. There are let's say the Builder patterns (no MVC). And this is the right place for reuse: Mark your Builder as the IMessageReporter and use the Messages the usuall way - Builder will report about incorrectness...

(Of course, finally evaluation of the Messages collection must be in a batch Library evaluated - because the built in messages reporting is built on MVC)


And the last piece of the Messages power comes with built in logging based on Log4NET which is called whenever the Message is inserted. (And when the Log4NET.config is set to track these logs)


Nice to see your deep experience. Thanks for that feedback. Please, if anything, do not hesitate and let me (us) know!

Enjoy Catharsis and look forward the latest release ... .)

Radim Köhler