Primary Redakt data and content is persisted in a document (NoSQL) database. A data connection is required for Redakt to function, and therefore your application will not start up unless you have correctly installed and configured a database module. Since the choice of database is a fundamental architectural decision, Redakt does not register a database module by default. Setting up and configuring a database is typically one of the first things you do when starting a new Redakt-based project.

Module list

Redakt supports database products from several different vendors out of the box. The following database modules are developed and maintained by Redakt. Click on the links for setup & configuration instructions.

Using the data layer for your custom data

In addition to Redakt data, you can easily use the database module to store your own custom data. Simply create a custom POCO class that derives from the DocumentEntity abstract class and add your own properties. After that, inject an IRepository<MyEntityClass> interface into any service where you want to have data access to your entity, and use the methods on the repository interface to retrieve and store data.

A collection will be created automatically the first time the repository is used. The name of the collection will be the same as the class name. Alternatively, you can decorate your class with the CollectionNameAttribute to set a different collection name to use.

See below for an example POCO entity class and service with constructor injection of the repository class.

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Redakt.Data.DocumentStore;
using Redakt.Data.DocumentStore.Configuration;

namespace MyWebApplication.Models
{
    [CollectionName("Persons")]  // Optionally set a different name for the database collection
    public class PersonEntity: DocumentEntity
    {
        public string FirstName { get; set; }

        public string LastName { get; set; }

        public DateTime? DateOfBirth { get; set; }

        // Dictionaries and other concrete collections are allowed, as well as nested data structures.
        public Dictionary<string, string> ProfileProperties { get; set; }

        [IgnoreDataMember]  // This property is not saved to the database
        public string FullName => this.FirstName + " " + this.LastName;
    }
}
using System;
using System.Collections.Generic;
using Redakt.Data.DocumentStore;
using MyWebApplication.Models;

namespace MyWebApplication.Services
{
    public class PersonService: IPersonService
    {
        private readonly IRepository<PersonEntity> _personRepository;

        public PersonService(IRepository<PersonEntity> personRepository)
        {
            _personRepository = personRepository;
        }

        public IAsyncEnumerable<DocumentEntity> FindWithMinimumAgeAsync(int age)
        {
            var fromDateOfBirth = DateTime.Today.AddYears(-age);

            return _personRepository.FindManyAsync(x => x.DateOfBirth >= fromDateOfBirth);
        }

        // .. etc.
    }
}

Custom implementation

If you want to store your Redakt data in a different database than the ones mentioned above, you can develop your own database module implementation. For this, you need to implement the following interfaces:

IDocumentStore

The IDocumentStore interface is the entry point for the database module. In most cases, you will also want to implement the IInitializableProvider interface for your database module to perform any data connection initialization on application startup.

Your IDocumentStore implementation must be registered as a singleton scope with the IoC container.

IRepository<T>

The IRepository<T> generic interface is responsible for the actual querying and saving of data. The interface contains methods that take a LINQ filter predicate parameter, therefore your database SDK should have a LINQ provider to process the filter predicates.

Your IRepository<T> implementation must be thread-safe and registered as a singleton scope with the IoC container.