Skip to content

InMemoryImplementation

Craig Fowler edited this page Feb 24, 2020 · 2 revisions

For writing unit tests, and perhaps for rapid prototyping, developers do not want the real ORM stack, they will want to use a substitute which is easier to set-up and control.

The package CSF.ORM provides a naïve in-memory implementation of the API for purposes such as these. This is not intended to be a production-quality implementation. It is intended for testing and prototyping only.

The entry-point to the in-memory implementation is the class CSF.ORM.InMemory.ConnectionFactory. This class implements CSF.ORM.ICreatesDataConnection, which facilitates the rest of the functionality in the ORM API.

The in-memory connection factory takes a single optional boolean constructor parameter named useSharedData. If set to false or omitted then each connection created using the factory will use a new/empty in-memory data-store. Objects added from one connection will not be 'visible' to another. This is the default because it is the most useful behaviour for unit-testing, where tests should not affect one another.

If the useSharedData parameter is specified and set to true then each connection created using the factory will use a shared in-memory data-store. This means that any/all data added/manipulated from any connection will be 'visible' to other connections from the same factory.

Clone this wiki locally