Skip to content

Document the configuration provider #2431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions doc/reference/modules/configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,45 @@ var session = sessions.OpenSession(conn);

</sect1>

<sect1 id="configuration-provider">
<title>Using a custom configuration provider</title>

<para>
By default, NHibernate attempts to read the <literal>hibernate-configuration</literal> section
through the .Net <literal>ConfigurationManager</literal>. Some environments do not support it, so
NHibernate provides a way to set a custom configuration provider, through the
<literal>NHibernate.Cfg.ConfigurationProvider.Current</literal> property.
</para>

<para>
To disable the configuration provider, in case you configure NHibernate entirely programmatically,
set this property to <literal>null</literal>.
</para>

<programlisting><![CDATA[ConfigurationProvider.Current = null;]]></programlisting>

<para>
To provide directly the <literal>System.Configuration.Configuration</literal> instance to use, assign
the <literal>Current</literal> property with an instance of
<literal>NHibernate.Cfg.SystemConfigurationProvider</literal> built with your
<literal>Configuration</literal> instance.
</para>

<programlisting><![CDATA[ConfigurationProvider.Current = new SystemConfigurationProvider(yourConfig);]]></programlisting>

<para>
You may also derive a custom provider from <literal>NHibernate.Cfg.ConfigurationProvider</literal>,
implements its abstract methods, and assign an instance of your custom provider to the
<literal>NHibernate.Cfg.ConfigurationProvider.Current</literal> property.
</para>

<para>
Changes of the <literal>ConfigurationProvider.Current</literal> property value are to be done very
early in the application lifecycle, before any other call on a NHibernate API. Otherwise they
may not be taken into account.
</para>
</sect1>

<sect1 id="configuration-optional">
<title>Optional configuration properties</title>

Expand Down