Initializing your global.asax for MVC and NHibernate’s ActiveRecord is really easy. There are really only two sections you need to touch: the using section and Application_Start().
Configure using section
Out of the box, you don’t have to do anything if you are NOT using ActiveRecord for CRUD. If you want to use ActiveRecord, here are the using statements you need to add:
using System.Reflection; using Castle.ActiveRecord; using Castle.ActiveRecord.Framework;
Those namespaces are used in the next section, which is
Application_Start()
There are only three lines of code to initialize ActiveRecord to specify the settings are sitting in web.config:
IConfigurationSource source = System.Configuration.ConfigurationManager.GetSection("activeRecord") as Castle.ActiveRecord.Framework.IConfigurationSource;
Assembly asm1 = typeof(Certification).Assembly;
ActiveRecordStarter.Initialize(new Assembly[] { asm1 }, source);
Those lines should appear BELOW the RegisterRoutes() call. If you don’t include the above lines, you will receive the following nastygram:
An ActiveRecord class (Contact) was used but the framework seems not properly initialized. Did you forget about ActiveRecordStarter.Initialize() ?





[...] to Vote[Del.icio.us] Initialize global asax in MVC for NHibernate ActiveRecord (6/4/2010)Friday, June 04, 2010 from [...]