<ReferenceData()> _ Public Class Gender Inherits Entity End Class2 and 3 are solved by our old friend the ObjectStore (oops I need to blog about this!) and some changes to our ServiceProvider class. This is the class that provides instances of services; DAL or Web service proxies. We use it like this:
Dim partyService As IPartyService = _ AIS.Service.ServiceProvider.GetServiceInstance(GetType(IPartyService))I've used a variant of the Gang-of-Four 'Decorator' pattern here so that when we ask for a service instance, we don't get a reference to a DAL or Web service, we get a reference to a 'Filter' that then in turn holds a reference to the DAL or web service. The Filter intercepts all the calls to the service allowing it to do numbers 2 and 3 above; cache the reference data when it's first loaded and map domain object's properties back to the cached reference data objects as they are loaded. The class that actually does all the work is called ReferenceProvider. Each filter has one of these. They are created by a ReferenceProviderBuilder object which our ServiceProvider class holds a reference to. We use the ReferenceProviderBuilder property of ServiceProvider to set up a new ReferenceProviderBuilder at application startup. The ReferenceProviderBuilder creates and holds a reference to the ObjectStore that's used to cache and retrieve reference data objects and then hands the object store to every ReferenceProvider that it creates. The ReferenceProviderBuilder class also has a property 'Mode' which is a enum with two values; 'Load' and 'Filter'. When the state passed to a ReferenceProvider is 'Load' it caches any reference data it sees in the object store, when the state is 'Filter', it looks for any reference data references in the returned object graph and binds the property to the cached referenced data object instead. So what does the developer have to do to use it? 1. Attribute all their reference data classes with the ReferenceDataAttribute as above. 2. Make sure that those reference data classes are cached at startup. 3. Don't get the reference data instances from the Data Access Layer when building object graphs.