Skip to content

Read Only DTO

stepaside edited this page Jul 18, 2012 · 4 revisions

Nemo provides an ability to guard each instance against modifications 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
Clone this wiki locally