Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cd21h committed Apr 17, 2016
1 parent 0359437 commit ad7d52e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 59 deletions.
10 changes: 10 additions & 0 deletions Artefacts/Documentation/source/nhibernate/multiple-dbs.rst
@@ -1,6 +1,16 @@
Multiple Databases
==================

Version 4.0
-----------

Due to refactoring of NHibernate session management S#arch v4.0 does not support multiple databases.
This feature will be added in 4.1.


Version 3
---------

To add support for an additional database to your project:

Create an NHibernateForOtherDb.config file which contains the connection
Expand Down
Expand Up @@ -7,41 +7,30 @@ NHibernate configuration data can reduce initial startup time by storing
the configuration to a file and avoiding the validation checks that run
when a configuration is created from scratch.

SharpArch's NHibernateSession class now has a ConfigurationCache
property that accepts an object reference that does the work of loading
and saving the NHibernate configuration to a file. This new feature is
based on an article by Oren Eini (aka Ayende Rahien) Building a Desktop
SharpArch provides interface :csharp:`INHibernateConfigurationCache`
and :csharp:`NHibernateConfigurationFileCache` class which caches configuration
in a file under system TEMP folder.

This new feature is based on an article by Oren Eini (aka Ayende Rahien) Building a Desktop
To-Do Application with NHibernate, and a big thanks to Sandor
Drieenhuizen who provided a lot of this code.

Cache Setup
-----------

To use the configuration cache simply set the
NHibernateSession.ConfigurationCache property to a new instance of the
NHibernateConfigurationFileCache class, before calling the
NHibernateSession.Init method. For example:
To use the configuration cache provide cache implementation to UseConfigurationCache() method
of the NHibernateSessionFactoryBuilder class:

::
For example:
..code-block:: csharp

private void InitializeNHibernateSession()
{
NHibernateSession.ConfigurationCache = new NHibernateConfigurationFileCache(
new string[] { "Northwind.Domain" });
NHibernateSession.Init(
webSessionStorage,
new string[] { Server.MapPath("~/bin/Northwind.Infrastructure.dll") },
new AutoPersistenceModelGenerator().Generate(),
Server.MapPath("~/NHibernate.config"));
}
}

The constructor of the NHibernateConfigurationFileCache class takes a
string array of file dependencies, typically this is the Domain.dll that
contains the web application's domain model objects. The string array
can contain just the assembly name (as above) or the file name (ex
"Northwind.Domain.dll") or the full path to the file (ex
"c:.Domain.dll").
ISessionFactory sessionFactory = new NHibernateSessionFactoryBuilder()
.AddMappingAssemblies(new[] { HostingEnvironment.MapPath(@"~/bin/Suteki.TardisBank.Infrastructure.dll") })
.UseAutoPersistenceModel(new AutoPersistenceModelGenerator().Generate())
.UseConfigFile(HostingEnvironment.MapPath("~/NHibernate.config"))
.UseConfigurationCache(new NHibernateConfigurationFileCache())
.BuildSessionFactory();


Details
-------
Expand All @@ -50,61 +39,49 @@ Details

INHibernateConfigurationCache

Interface that defines two methods for loading and saving the
configuration cache.
Interface that defines two methods for loading and saving the configuration cache.

NHibernate.Cfg.Configuration LoadConfiguration(string configKey, string
configPath, string[] mappingAssemblies) void SaveConfiguration(string
configKey, NHibernate.Cfg.Configuration config)
..code-block:: csharp
NHibernate.Cfg.Configuration LoadConfiguration([NotNull] string configKey, string configPath, [NotNull] IEnumerable<string> mappingAssemblies);
void SaveConfiguration([NotNull] string configKey, [NotNull] NHibernate.Cfg.Configuration config);

These methods are used by the NHibernateSession.AddConfiguration method
to load and save a configuration object to and from a cache file. This
interface allows others to implement their own file caching mechanism if
necessary.

These methods are used by the NHibernateSession.AddConfiguration method to load and save a configuration object to and from a cache file.
This interface allows others to implement their own file caching mechanism if necessary.

::

NHibernateConfigurationCache
NHibernateConfigurationFileCache

This class implements the interface and does the work of caching the
configuration. Several methods are virtual so they can be overridden in
a derived class, as may be necessary to store the cache file in a
This class implements the interface and does the work of caching the configuration.
Several methods are virtual so they can be overridden in a derived class, as may be necessary to store the cache file in a
different location or to have different logic to invalidate the cache.

The constructor takes an string array of file dependencies which are
The constructor takes an optional string array of file dependencies which are
used to test if the cached NHibernate configuration is current or not.
If any of the dependent file's last modified time stamp is later than
that of the cached configuration, then the cached file is discarded and
a new configuration is created from scratch. This configuration is then
serialized and saved to a file.

Note: NHibernate's XML config file and the mapping assemblies (ex
"Northwind.Data.dll") are automatically included when testing if the
cached configuration is current.
Note: NHibernate's XML config file and the mapping assemblies (ex: "Northwind.Data.dll")
are automatically included when testing if the cached configuration is current.

FileCache
---------

The SharpArch.Domainproject now contains a FileCache class that can
The SharpArch.Domain project now contains a FileCache class that can
serialize and deserialize an object to a file in binary format. This
class uses a generic type parameter to define the type being serialized
and deserialized. This makes the FileCache class useful for any other
object that you might want to serialize to a file.

ConfigurationCache property
---------------------------------------------

This property holds a reference to an INHibernateConfigurationCache
object, and if not null, will use the caching logic to load and save the
NHibernate configuration. You must set the ConfigurationCache property
before calling the NHibernateSession.Init method, and you cannot change
the property reference after calling the Init method.

Configuration Serialization
---------------------------

To cache the configuration to a file, all objects contained within the
NHibernate configuration must be serializable. All of the default data
NHibernate configuration **must be serializable**. All of the default data
types included with NHibernate will serialize, but if you have any
custom data types (i.e. classes that implement IUserType), they must
also be marked with the [Serializable] attribute and, if necessary,
Expand Down
6 changes: 5 additions & 1 deletion Artefacts/Documentation/source/nhibernate/transaction.rst
@@ -1,4 +1,8 @@
NHibernate Transaction attribute
================================

TODO
TransactionAttribute implements Unit of work pattern for ASP.NET MVC and ASP.NET WebAPI controller.

Please refer to TardisBank sample for details.

TODO: update documentation.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -19,20 +19,20 @@ Building S#arp Architecture
--------------------------------------------

Perform the following command in GitBash:

```Shell
$ git clone git@github.com:sharparchitecture/Sharp-Architecture.git
$ git submodule init
$ git submodule update

Now you should have the latest development branch of SA 2.0 and submodules.
```
Now you should have the latest development branch of S#arp Architecture and submodules.

Now go to /Build and run the Build.cmd or BuildAndPackage.cmd files to build S#arp Architecture

--------------------------------------------
Documentation and Assemblies
--------------------------------------------

* /Artefacts/Documentation/: Contains a link to comprehensive, online documentation at http://wiki.sharparchitecture.net/, and a diagram of what a S#arp Architecture project looks like.
* /Artefacts/Documentation/: Contains a link to comprehensive, online documentation at http://sharp-architecture.readthedocs.org/, and a diagram of what a S#arp Architecture project looks like.

* /Drops/<Version Number>/: Holds released SharpArch assemblies - it does not include the third party library's that are needed by S#arp Architecture. You must run the BuildAndPackage.cmd file first.

Expand Down

0 comments on commit ad7d52e

Please sign in to comment.