views:

49

answers:

3

Hi, I am building a questionnaire creator. A questionnaire consists of sections, sections consist of pages and pages consist of questions. Questionnaire is the aggregate root.

Sections, pages and questions can have what are called shortcodes which should be unique within a questionnaire (but not unique within the database hence they are not strictly an identity). I intended to make the shortcode a value object and wanted to include the business rule that it should be unique within the questionnaire but I am unsure how to ensure that. My understanding is that the value object should not access the repository or service layer so how does it find out if it is unique?

Thanks for any help.

Darren

A: 

Clearly, you are going to need a PK field in the database. How you implement that is up to you, but if it were me, I'd carry the PK field into your value object so that it is handled automatically.

Robert Harvey
A: 

You would want to use something like a Guid or UUID. Exactly how you would generate one would depend on what language you are using for your application though.

Eric Petroelje
A: 

You could assign the responsibility of generating shortcodes to the questionnaire aggregate. It can be based on a simple counter embedded into questionnaire object. Every entity that want to create a shortcode would call its containing questionnaire's NextShortCode() method to obtain next unique (in scope of current questionnaire) shortcode value.

Szymon Pobiega