Hi,
I have recently noticed the namespace for Cuyahoga.Modules.User contains two seperate modules - UserModule and ProfileModule.
We are developing a single module in its own namespace and I was wondering if it's acceptable to have multiple modules defined in a single namespace/DLL. This provides great flexibility to share the same Domain objects, within a single namespace, across multiple modules. Each module having its own ascs controls defined.
1) Is this a recommended design solution for any module/namespace or is this something that Cuyahoga Core modules can only take advantage of?
Thanks,
Jmas
It is perfectly possible to have multiple modules in one assembly but there can be some issues depending on the Cuyahoga version being used.
If your module uses NHibernate - when installing your module, the assembly will be added to the NHibernate configuration, which means ALL NHibernate classes in your dll will be added to config (even the ones from another "logical" module).
So this can lead to doubled config entries and corresponding errors. There is a fix in the trunk but I am not sure if this has been backported to older versions.
Thanks Mgaerber,
I am currently using Cuyahoga version 1.5.0.
Also, based on the releasenotes.txt:
Libraries:
- Using Castle Windsor IoC container with the NHibernateIntegration and
AutomaticTransaction facilities.
- Upgraded NHibernate to 1.0.4
- Upgraded Npgsql to 1.0
- Upgraded FCKeditor to 2.3.2
Module_A = modules.assembly, modules.assembly.Module_A, Modules/assembly/Module_A.ascx
Module_B = modules.assembly, modules.assembly.Module_B, Modules/assembly/Module_B.ascx
Each module uses/shares the same NHibernate domain objects of my single assembly.
Each module has a seperate ModuleService entry in the DB.
Each module has a seperate ModuleType in the ModuleType DB table.
Each module has a seperate DAO object and Interface.
Each module has a seperate "Controller" class for DAO contructor injection.
1) Are these errors End-User run-time errors, or do they only occur when installing the modules using the admin UI?
2) Since I'm not real familiar with how NHibernate manages the domain objects, how and where is the module's assembly added to the NHibernate configuration? Is this an in-memory configuration?
3) I have noticed the cuyahoga_version table contains two references to my assembly, is this where NHibernate places them?
4) Is this fix documented or easy to download and integrate into my current version of source?
5) Can you or someone point me to the files that have the fix implemented?
Thanks again for your help,
Jmas
Hi Martijn,
I am trying to assess the risk in creating and using multiple modules in a single DLL. See above for explanation of how I am doing this.
1) Can you provide any feedback in this area.
2) Has the fix been made in the 1.5.0 version of Cuyahoga?
3) If not, do you have any details on this fix, so I might apply this fix to a 1.5 version.
4) Should I not go down this path at all, until version 2.0 is ready.
Thanks,
Jmas
The problem is in the ModuleLoader class (see
http://cuyahoga.svn.sourceforge.net/viewvc/cuyahoga/branches/1.5.x/Web/Components/ModuleLoader.cs?view=markup )
On line 136 a call is made to register the mappings.
In the trunk this code has been modified to make a lookup if this assembly has already been mapped for NHibernate:
//make sure we haven't already added this assembly
if (typeof(INHibernateModule).IsAssignableFrom(moduleTypeType) && ((HttpContext.Current.Application[moduleType.AssemblyName]) == null))
{
this._sessionFactoryHelper.AddAssembly(moduleTypeType.Assembly);
//set application variable to remember the assemblies
HttpContext.Current.Application[moduleType.AssemblyName] = moduleType.AssemblyName;
}
You could use this check but be sure to lock your app when setting global data. Taking more code out of the trunk wouldn't be wise since there have been major changes.
Thanks again Mgaerber,
You wrote:
"You could use this check but be sure to lock your app when setting global data."
By setting global data, do you mean setting global "static" data within my module specifically?
By setting global data, do you mean setting global "static" data within my module specifically?
I just wanted to remember to use Application.Lock / Unlock or Monitor.Enter / Exit calls around such code that handles global (application level) data.
Otherwise two threads could try to set the values at the same time and the whole checking is useless