Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We took a slightly different approach to solving this problem using the 1.3.x version of FNH, with a few specific design goals in mind:</p> <ul> <li>Keep our domain entities POCO.</li> <li>Take advantage of the FNH auto-persistence mechanism.</li> <li>Package IAutoMappingOverride instances in the assembly with the entities on which they depend.</li> <li>Allow the "plug-in" of new assemblies containing mapped entities without having to alter the core FNH configuration.</li> </ul> <p>Much like the OP's solution, all of our mapped entities inherit from a set of well-known base classes. Armed with this and the fact that AutoPersistenceModel.UseOverridesFromAssembly() can indeed be called multiple times, we were able to make a simple modification to our auto-mapping configuration class to dynamically add the override assemblies:</p> <pre><code>internal sealed class SessionConfiguration : DefaultAutomappingConfiguration { public AutoPersistenceModel PersistenceModel { get { Assembly[] assembliesToMap = MappedAssemblyResolver.GetMappedAssemblies(); AutoPersistenceModel model = AutoMap.Assemblies(new SessionConfiguration(), assembliesToMap); foreach (Assembly potentiallyMapped in MappedAssemblyResolver.GetOverrideAssemblies(assembliesToMap)) { model.UseOverridesFromAssembly(potentiallyMapped); } model.Conventions.AddFromAssemblyOf&lt;SessionConfiguration&gt;(); // other FNH configuration options omitted return model; } } public override bool ShouldMap(Type type) { return type.IsSubclassOfRawGeneric(typeof(DomainObject&lt;&gt;)); } } </code></pre> <p>MappedAssemblyResolver looks something like this: </p> <pre><code>internal static class MappedAssemblyResolver { public static Assembly[] GetMappedAssemblies() { Assembly[] mappedAssemblies; // TODO: implement your strategy for resolving assemblies return mappedAssemblies; } public static IEnumerable&lt;Assembly&gt; GetOverrideAssemblies(Assembly[] mappedAssemblies) { mappedAssemblies.CheckNull("mappedAssemblies"); return mappedAssemblies; } } </code></pre> <p>A few items of note: </p> <ol> <li>DomainObject is our base domain entity. It contains common things like Id, DateCreated, etc.</li> <li>IsSubclassOfRawGeneric(Type) is an extension method, available <a href="https://gist.github.com/3289331" rel="nofollow">here</a>.</li> <li>CheckNullOrEmpty(string) is an extension method, available <a href="https://gist.github.com/3403869" rel="nofollow">here</a>.</li> <li>You'll need to implement a way of actually resolving your assemblies in GetMappedAssemblies(). We do some inspection of AppDomain.CurrentDomain and them apply some rules to determine which assemblies we consider to be matches.</li> </ol> <p>Also note that, while we're putting the IAutoMappingOverride instances in the same assembly as our entities, you could easily change the implementation of GetOverrideAssemblies(Assembly[]) if your goal was to further decouple your domain from FNH.</p> <p>Either way, this should allow you to add new mapped entities (or new assemblies containing them) and their related mapping overrides at will without giving much thought to their addition to the underlying FNH AutoPersistenceModel.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload