This is a simple tip, I’ve used the Castle Windsor NHibernate Integration Facility to build up the data access services in one of the projects I’m working on, I also wanted to use the NHibernate SchemaExport utilities to build up the database from scratch, this can be very useful when using SQLite in a testing environment.
Since the facility is configured with XML files, I had the problem on how to access the NHibernate.Cfg.Configuration object; having a look at the source code of the Integration Facility it turns out that the Configuration object are registered in the container too along with the factories (one configuration and one factory for each element declared in the configuration file), an alias name is assigned to each configuration object in the form of: {factory_id}.cfg.
So if you have the following settings:
<facility id="nhibernatefacility" isweb="true" type="Castle.Facilities.NHibernateIntegration.NHibernateFacility,Castle.Facilities.NHibernateIntegration"> <factory id="MainDatabase" alias="nh.facility.default"> <settings> <item key="connection.provider">NHibernate.Connection.DriverConnectionProvider</item> ... </settings> <assemblies> <assembly>YourAssembly</assembly> </assemblies> </factory> </facility>
[Test, Explicit] public void CreateDatabaseSchema() { NHibernate.Cfg.Configuration cfg = Container.Resolve<NHibernate.Cfg.Configuration>("MainDatabase.cfg"); SchemaExport export = new SchemaExport(cfg); export.Execute(false, true, false); }
Related Content
- Castle Windsor WCF Services Resolution Facility (26/08/2015)
- Castle Windsor enabling XML configuration files in Silverlight (26/08/2015)
- Castle Windsor - resolve dependencies on an existing object instance (26/08/2015)
- Silverlight / Castle Windsor – implementing a simple logging framework (26/08/2015)
- Silverlight / Castle Windsor – how to use a logging framework properly (26/08/2015)
- More related document (33)