문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top