No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



BellaCode.Storage is a .NET class library that provides a simple and flexible abstraction from Create, Retrieve, Update, Delete (i.e. CRUD) storage implementations. It can abstract away file system, database, or service storage APIs.

The general purpose interfaces can be used to quickly create repositories for Online Transaction Processing (OLTP) applications and sites. Rather than write the same IO code over and over, you can instantiate a simple storage class and start loading and saving your items from storage.

While made open source in 2016, this library has been used since 2013 on a multitude of projects spanning Windows WPF applications. Windows console applications, ASP.NET web APIs, and ASP.NET MVC web sites. The lockable storage interfaces allow for fast multi-threaded and multi-user services backed by storage.


BellaCode.Storage supports many storage scenarios. These scenarios were developed and refined to readily handle configuration, multi-record, and multi-threaded storage needs.

I can load and save items

IStorage<TKey,TItem> provides basic storage functions that let you store items at the specified location. Using this interface is a lot like using The System.IO.File class where your keys are paths to the disk.

  • DoesExist()
  • GetCreatedDateTime() (UTC)
  • GetModifiedDateTime() (UTC)
  • Load()
  • Save()
  • Delete()

I can synchronize the load and save of items

ILockableStorage<TKey, TItem> extends IStorage to provide locking semantics for reads/writes.

  • IsLocked()
  • Lock()
  • WaitForLock()
  • Unlock()
  • Load() (with lock token)
  • Save() (with lock token)

I can load and save items at a well-known single location

ISoloStorage provides the similar methods to IStorage, but without requiring a key per item to save. Instead, ISoloStorage implementations are provided the storage location during construction.

I can load and save items using a key-location map

MappedStorage<TPrimaryKey, TForeignKey, TItem> implements IStorage. It allows a mapping function to determine the location where each item is stored based on a key. A common pattern is to map an items unique identifier (GUID) to a file path or storage table index.

I can load as save items to files in common formats

The BellaCode.Storage.Files project provides file-based implementations. FileStorage is an abstract base class that implements IStorage and ILockableStorage.

  • JsonFileStorage lets you load/save files in JSON format using the popular JSON.NET NuGet package.
  • XmlFileStorage lets you load/save files in XML format using the XmlSerializer.
  • BinaryFileStorage lets you load/save files using the BinaryFormatter.

I can compose storage implementations

OK, this is more of a scenario for implementors of storage interfaces. For example, ISoloStorage can be implemented by using an IStorage implementation.

  • SoloStorage implements ISoloStorage via IStorage implementation and either a well-known key or a key locator.
  • LockableSoloStorage implement ILockableSoloStorage via ILockableStorage implementation
  • MappedStorage implements IStorage via an underying IStorage implementation and a key converter
  • LockableMappedStorage implements ILockableStorage via an underying IStorage implementation and a key converter.

These sound complex, but the code is very straightforward.

Usage Examples

The StorageExamples command-line project demonstrates how to use each of the storage types.