After hours of hacking at NHibernate, I found a compromised solution on how to keep domain level classes isolated from the infrastructure level. Only one “victim” here is point number 1 in the list below:
1) I introduced the DomainObject base class for all persistent objects in a domain with only one private field:
private IDictionary _infrastructureProperties = new Dictionary<object, object>();
2) Added the following section to class mapping:
<dynamic-component name='_infrastructureProperties' access='field'> <property name='CreateBy' column='CreatedBy' /> <property name='CreateDate' column='CreatedDate' /> </dynamic-component>
3) An interceptor has been introduced that sets these property values.
4) Optional. We could also implement good settings with the setting that the "role" of each class plays in the application, and then to work with certain properties of the role in Interceptor. For instance. this configuration may indicate that Product is a TenantScopeObject, and the interceptor will set the TenantID property to the current tenant ID registered in the system.
source share