This package provides an NHibernateProjector that allows you to build NHibernate-backed projectors for use with LiquidProjections' event mapping API and Dispatcher class.
- Supports NHibernate 4.0 or later.
- Allows customizing how many LiquidProjections Transactions it should process in a single database transaction.
- Supports nesting one or more
NHibernateChildProjectors that can be used for maintaining lookup tables and which are part of the same database transaction as the parent projector creates. - Ensures autonomy by storing the
IProjectionState(e.g. the last transaction checkpoint) in the same transaction as the actual projection data. - Exposes the
ShouldRetrydelegate so that you can handle projection exceptions and get full control on whether or not the projector should retry (again). - If the implementation of
IProjectorState has additional custom properties, you can use theEnrichStatedelegate of theNHibernateProjectorto update the state object before it is written to the database. This is called as part of the same database transaction that encompasses the projector code.
This package provides a simple caching mechanism in the form of the IProjectionCache and ships with the LruProjectionCache based on the FluidCaching project. The IProjectionCache is meant for the most common scenarios and thus has some limitations:
- If the projector performs database modifications directly on the NHibernate
ISession, that projector must make sure the cache is updated or cleared accordingly. - The cache doesn't understand relationships where a projection refers to another projection maintained by the same projector. For instance, a projector that maintains a graph of parents and children, where a child is also a (direct or indirect) parent must use a more advanced type of caching.
If you need more advanced caching, please refer to NHibernate's Second Level Caching feature.
Check out the unit tests to learn how the many features work together. You can also look at the non-NHibernate example here and replace Projector with NHibernateProjector. A proper example project for NHibernate is planned.