Quote:
Also, I don't understand what you mean by "passing in" several assemblies.
By that I mean the signature of a method that can take a collection or an array of assemblies as an argument. If you use AddAssembly, that take only one assembly as an argument, then the method will throw an exception saying that it cannot find the class B referenced by the mapping and residing in another other assembly, when resolving class A, where class A resides in the passed in assembly. As far I've seen, the methods looks for hbm.xml files or use GetTypes() on one specific (passed in) assembly.
Code:
configuration.AddAssembly(myAssembly);
So since I would avoid any custom modification of the really nice NHibernate libraries, I wonder which methods you refer to when you say that
Quote:
NHibernate already supports multiple domain assemblies without any problems
.
Here's is a copy of the AddAssembly methods available on the configuration class:
Code:
/// <summary>
/// Adds all of the assembly's embedded resources whose names end with <c>.hbm.xml</c>.
/// </summary>
/// <param name="assemblyName">The name of the assembly to load.</param>
/// <returns>This configuration object.</returns>
/// <remarks>
/// The assembly must be loadable using <see cref="Assembly.Load(string)" />. If this
/// condition is not satisfied, load the assembly manually and call
/// <see cref="AddAssembly(Assembly)"/> instead.
/// </remarks>
public Configuration AddAssembly(string assemblyName)
Code:
/// <summary>
/// Adds all of the assembly's embedded resources whose names end with <c>.hbm.xml</c>.
/// </summary>
/// <param name="assembly">The assembly.</param>
/// <returns>This configuration object.</returns>
/// <remarks>
/// This method assumes that the <c>hbm.xml</c> files in the Assembly need to be put
/// in the correct order by NHibernate. See <see cref="AddAssembly(Assembly, bool)">
/// AddAssembly(Assembly assembly, bool skipOrdering)</see> for the impacts and reasons
/// for letting NHibernate order the <c>hbm.xml</c> files.
/// </remarks>
public Configuration AddAssembly(Assembly assembly)
Unless I'm really mistaken here, I cannot see how invoking the AddAssembly method passing in my assembly instance as a parameter to the method can solve my problem when I need the method to map several assemblies that together make the DB.
Since I use attributes and don't have any xml files, then using these methods won't help me either. I have to extract the attributes and generate my xml file(s) first, and then it is natural to use the HbmSerializer. And also in this class I have not found any methods that can take an array or a collection of assembly instances as an argument:
Code:
/// <summary> Writes the mapping of all mapped classes of the specified assembly in the specified hbm.xml file. </summary>
/// <param name="assembly">Assembly used to extract user-defined types containing a valid attribute (can be [Class], [Subclass] or [JoinedSubclass]).</param>
/// <param name="filePath">Where the xml is written.</param>
public virtual void Serialize(System.Reflection.Assembly assembly, string filePath)
/// <summary> Writes the mapping of all mapped classes of the specified assembly in the specified stream. </summary>
/// <param name="stream">Where the xml is written.</param>
/// <param name="assembly">Assembly used to extract user-defined types containing a valid attribute (can be [Class], [Subclass] or [JoinedSubclass]).</param>
public virtual void Serialize(System.IO.Stream stream, System.Reflection.Assembly assembly)
/// <summary> Writes the mapping of all mapped classes of the specified assembly in a MemoryStream and returns it. </summary>
/// <param name="assembly">Assembly used to extract user-defined types containing a valid attribute (can be [Class], [Subclass] or [JoinedSubclass]).</param>
/// <returns>Stream containing the XML mapping.</returns>
public virtual System.IO.MemoryStream Serialize(System.Reflection.Assembly assembly)
As I've got mappings of some types to be persisted in assembly G that is common across domains, then many of my classes residing in assembly A references the classes in the general assembly G. Passing in just assembly A will throw an exception saying that referenced type cannot be mapped (or something like that, I don't remember the exact phrasing at the moment). Therefore I wonder what method(s) I should have invoked instead, to use the already existing support for multiple assemblies.
By using the method posted in the first posting of this thread, this case is no problem at all.