We can combine both. There is an example, reading the configuration first, then extending it with as many settings as needed:
ISessionFactory CreateSessionFactory(string connectionString) // from outer source
{
// the Configuration, i.e.: native, NHibernate one
var configuration = new NHibernate.Cfg.Configuration();
var configFile = ... // a path to configuration ;
// read that configuration file
var document = XDocument.Load(configFile);
// pass it to the Configuration
using (var reader = document.CreateReader())
{
configuration.Configure(reader);
}
// so, the config file is applied,
// no its our dynamic turn
configuration.SetProperty("connection.connection_string", connectionString);
configuration.SetProperty(....);
// and now, we can ask for configuration to produce the factory
var factory = configuration.BuildSessionFactory();
return factory;
}