Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# matthewnichols 8/21/2006 11:50 AM
I am writing a bookmarking module and the way I layed it out the object model is in a seperate assembly from the module itself. All went fine when I had it managing it's own NHibernate session but when I try to use cuyahoga's existing session I get errors say that the class isn't recognized. As I look around it seems to make sense as it seems that any thing implementing INHibernateModule (is that right...not in front of my dev box at the moment) is scanned for classes requiring persistence. So my classes are never seen as they don't exist in the module itself.

So it seems like I need to register these classes or the assembly where they live with cuyahoga. Is there a prefered method for doing this? I was poking arouund Coe.Services yesterday and thought I was close, but I suspect that this an obvious thing to my betters.

BTW is there the beginings of a Module development guide for the new architecture? It seems like the one on the site is not the most up to date for the new stuff. If not I would be willing to take it on (with much pestering of others I am sure) as it would have me get this stuff flat for myself.

Thanks,

Matthew Nichols

matthew at matthew dash nichols dot com
# gedw99 8/21/2006 5:11 PM
Mat,

i have the same problem too about dealing with some of the plumbing od the new Castle based architecture.

Can there be soem effort to get this information perhaps?

Ged
# martijnb 8/21/2006 6:19 PM
matthewnicholsSo it seems like I need to register these classes or the assembly where they live with cuyahoga. Is there a prefered method for doing this? I was poking arouund Coe.Services yesterday and thought I was close, but I suspect that this an obvious thing to my betters.

That's an interesting one! Starting from 2.0, modules don't have to register domain classes anymore when they are in the same assembly as the module controller (and the module controller implements the INHibernateModule.
Now, when you want to register external classes, you'll need a reference to the SessionFactoryHelper class in the module controller. Since these kinds of dependencies can be resolved automatically now via dependency injection, it's very easy to add this to the module controller (we'll use the constructor injection here):
public class MyModule : ModuleBase
{
  private SessionFactoryHelper _sessionFactoryHelper;

  public MyModule(SessionFactoryHelper sessionFactoryHelper)
  {
    _sessionFactoryHelper = sessionFactoryHelper;

    [... get an instance of the assembly class that defines the assembly where the domain classes are located]

    _sessionFactoryHelper.AddAssembly(myAssembly);

  }
}

I'll add an extra method to SessionFactoryHelper that accepts a single class.
Btw, the old SessionFactory class is still working fine, to ensure proper working of existing modules. You can still use that for the time being.
BTW is there the beginings of a Module development guide for the new architecture? It seems like the one on the site is not the most up to date for the new stuff. If not I would be willing to take it on (with much pestering of others I am sure) as it would have me get this stuff flat for myself.

You bring up a good point here. I'll see what I can do about it after the next release, unless somebody else wants to take care of this?
# El Gringo 9/12/2006 6:36 AM
martijnbBtw, the old SessionFactory class is still working fine, to ensure proper working of existing modules. You can still use that for the time being.

Hello Martijn,

thank you for the tips. I used the old SessionFactory an added a class to it.
            SessionFactory sf = SessionFactory.GetInstance();
            sf.RegisterPersistentClass(typeof(MyClass));
            sf.Rebuild();
That didn't work. The class was found, but not the the hbm.xml.

I will try your first suggestion now.

Ricardo
# dagda1 9/12/2006 7:53 AM
Hi,

You can add your own assemblies to the ~/Config/facilities.config:

You just a new assmebly element to the parent assemblies element below the Cuyahoga.Core entry and it will be picked up without registering your classes with code.

Also if you need to use a different database, you can create a new factory element and give it an alias attribute, this element can contain the new connection string.

Paul
# El Gringo 9/12/2006 10:28 AM
Thanks Paul,
dagda1You can add your own assemblies to the ~/Config/facilities.config:

You just a new assmebly element to the parent assemblies element below the Cuyahoga.Core entry and it will be picked up without registering your classes with code.

I think this will be more a way for integrated modules. If you write a custom module having to modify some config files is not very nice.

I used the SessionFactoryHelper (mentioned by Martijn a few posts before) to integrated this, as you can do everything in the module.
dagda1Also if you need to use a different database, you can create a new factory element and give it an alias attribute, this element can contain the new connection string.

That is a good idea, I will give it a try. I am indeed using different databases in an external dll. But at the moment I am using the schema attribute in the class tag of the mapping file. This works perfectly and you can use this class even with the same session.

Ricardo
# dagda1 9/13/2006 3:26 AM
Hi Gringo,

I have never heard of the schema attribute or using multiple databases in this way, do you have an example of how I would do this.

Or really which way would I choose over the other?

Thanks

Paul