Skip to content

Read Only DTO

stepaside edited this page Oct 18, 2012 · 4 revisions

Nemo provides an ability to guard each POCO or DTO instance against modifications as well as preventing those objects from participating in CRUD operations, thus facilitating immutability. For this feature to work a DTO must be defined as an interface. This feature works on the whole object graph and not just top level properties.

// Retreive an ICustomer instance
var customer = ObjectFactory.Retrieve<ICustomer>(parameters: new ParamList { CustomerID => "ALFKI" }).First();
// Create a read-only ICustomer instance
var customer_read_only = customer.AsReadOnly();
customer_read_only.CompanyName = "New Company"; // This will throw NotSupportedException
customer_read_only.Delete(); // This will throw NotSupportedException
Clone this wiki locally