This post may be outdated. For the latest Domain Components concepts and examples refer to the current online documentation.
Notes, every business needs them. Every person in the company who has contact with a customer has to be able to record that fact in a CRM system. The last thing you want to do is to be a salesmen phoning a customer, in the hope of getting a large order, only to discover that the last contact the customer had with your company was to complain bitterly about the shoddy service he just received. If there was a note in the system to that fact, then you could either phone once it’s been resolved, or you could change your sales tactic.
Of course, saying you need notes is one thing, actually implementing it is quite another, especially if your class hierarchy already exists. You have to introduce the Note type, you have to create a member on the business objects to hold that new type, and most painful of all, you have to make room on the UI for the new note type. All and all you are in a world of pain. Now XAF can help you with the UI stuff, it will scaffold an appropriate UI for your types, but that still doesn’t save you from the pain of all the changes you have to make to your types.
Well enter Domain Components to save the day! The Domain Component technology will do all that hard work for you. First, let’s declare an INote interface:
[DomainComponent]
[XafDefaultProperty("Title")]
public interface INote {
[RuleRequiredField(NoteValidationRules.NoteTitleIsRequired, DefaultContexts.Save)]
[FieldSize(255)]
string Title { get; set; }
[FieldSize(4000)]
string Description { get; set; }
IPersistentFileData Attachment { get; set; }
}
As you can see it has a mandatory title property, so that you can name your note something meaningful, a description field, big enough to hold a reasonable sized note, and a field to hold an attachment, in case you wish to append a file to the note. Oh, and here’s the NoteValidationRules class that we’ve used in the RuleRequiredField:
public class NoteValidationRules {
public const string NoteTitleIsRequired = "NoteTitleIsRequired";
}
This pattern let’s us extend this behaviour, if we need to, at a later date.
So far so good, but it’s not really useful to have one note attached to a business class, what we really need is a notes collection, so let’s go ahead and define something to hold a collection of notes:
[DomainComponent]
public interface INotes {
[DevExpress.ExpressApp.DC.Aggregated]
IList<INote> Notes { get; }
}
This notes interface that we’ve just created is a pluggable part of the notes extension and now we can use it wherever we wish:
public interface ICRMActivity : IActivity, INotes ...
public interface ICRMContact : IContact, INotes, ...
public interface ICRMInvoice : IInvoice, INotes, ...
And so on and so forth.
So, as you can see, Domain Components, have saved us an awful lot of work when it comes to adding this notes functionality. After it has been added to the Contact, the UI looks like this:

And it looks like this, when added to the Invoice:

As you can see, in this post, I have not covered testing, neither unit testing, with something like NUnit, nor functional testing with EasyTest. I didn’t add the testing stuff in as I thought it might complicate matters, but if you feel that it wouldn’t and you’d like to see testing covered in this series, then let me know in the comments and I’ll add it to the next one.
Well, that’s all for this post, until next time, happy XAF’ing! 