Skip to content

Instantly share code, notes, and snippets.

@jagregory
Created February 9, 2009 23:29
Show Gist options
  • Select an option

  • Save jagregory/61097 to your computer and use it in GitHub Desktop.

Select an option

Save jagregory/61097 to your computer and use it in GitHub Desktop.
// special interface for overriding automaps
public interface IMappingOverride<T>
{
void Override(AutoMap<T> mapping);
}
// special config chunk for using above
public class SupplyMappingOverridesChunk : IAutoMappingConfigChunk
{
private readonly Assembly assembly;
public SupplyMappingOverridesChunk(Assembly overridesAssembly)
{
assembly = overridesAssembly;
}
public void Configure(AutoPersistenceModel model)
{
foreach (var type in assembly.GetTypes())
{
if (!type.IsSubclassOf(typeof(IMappingOverride<>))) continue;
// create auto map for type, and execute the
// IMappingOverride<T>.Override method against it
model.AddMapping(mapping);
}
}
}
// which is used through this on the AutoPersistenceModel
public AutoPersistenceModel WithMappingOverridesFromAssemblyOf<T>()
{
return WithConfigurationChunk(new SupplyMappingOverridesChunk(typeof(T).Assembly));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment