Hide

YetaWF Documentation

Display
Print

Data Providers

YetaWF stores most data in table format. Data tables can be located in files, SQL DBs, RavenDB documents, or many other data repositories. Applications always access data through an application data provider.

Application Data Provider

An application data provider is the high-level API used by an application to access data in table format. An example of an application data provider is the class YetaWF.Modules.Blog.DataProvider.BlogCategoryDataProvider, which provides access to blog categories and supports browse, read, update and remove methods.

The following example shows how an application data provider is obtained by an application and used to add one record.

using (BlogCategoryDataProvider dataProvider = new BlogCategoryDataProvider()) {
    if (!await dataProvider.AddItemAsync(model.GetData())) {
        ModelState.AddModelError(nameof(model.Name), this.__ResStr("alreadyExists", "A blog category named \"0\" already exists.", model.Category));
        return PartialView(model);
    }
    return FormProcessed(model, this.__ResStr("okSaved", "New blog category saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule);
}

AppSettings.json

Application data providers can be configured using AppSettings.json. Each data provider supports its own set of properties, which should be documented in each application data provider. The AppSettings.json settings determine where the data is stored and which low-level data provider is used.

Low-Level Data Provider

An application data provider (like BlogCategoryDataProvider above) doesn't directly perform I/O. While the application data provider determines the data location and format, it defers to a low-level data provider to read/write all data. YetaWF includes low-level data providers for SQL DBs and File I/O. Low-level data providers for other data repositories (like RavenDB) were created, they are not part of the open source project.

Low-Level Data ProviderDescription
FileImplements record-based I/O using the file system.
SQLImplements record-based I/O using SQL databases using stored procedures.
SQLDynImplements record-based I/O using SQL databases using dynamic SQL.
PostgreSQLImplements record-based I/O using PostgreSQL databases.

Low-level data providers all offer the same basic support as they implement the following interfaces:

InterfaceDescription
YetaWF.Core.DataProvider.IDataProvider<KEYTYPE,OBJTYPE>This interface is implemented by low-level data providers that offer access to record-based data with one primary key, without record identity.
YetaWF.Core.DataProvider.IDataProviderIdentity<KEYTYPE,KEY2TYPE,OBJTYPE>This interface is implemented by low-level data providers that offer access to record-based data with up to two primary keys and a record identity.
YetaWF.Core.DataProvider.IDataProviderTransactionsThis interface is implemented by low-level data providers to support transactions that can be committed, saving all updates, or aborted to abandon all updates. While always implemented by all low-level data providers, support for transactions may not be available.
System.IDisposableProvides a mechanism for releasing unmanaged resources.

A low-level data provider may take advantage of the available core data providers and local/shared caching provided by YetaWF.

Core Data Providers

YetaWF provides some basic "core" data providers, which may be used by low-level data providers and data providers in general.

Core Data ProviderDescription
YetaWF.Core.IO.CachingImplements local, shared and static caching.
YetaWF.Core.IO.DataFilesProviderImplements data files and supports retrieval of folders with data files.
YetaWF.Core.IO.FileIO<TObj>Implements file I/O for one object of type TObj.
YetaWF.Core.IO.FileSystemImplements filesystem access to a permanent and a temporary repository.
YetaWF.Core.IO.SessionStateIO<TObj>Implements .NET session state I/O for an object of type TObj.

Module Data Providers

YetaWF provides a module data provider that implements a module repository, where all module data is stored.

Module Data ProviderDescription
YetaWF.DataProvider.ModuleDefinition PackageThe package supports file I/O and SQL tables for module data.

A module data provider is a special type of data provider. It installs itself during application startup by providing access methods in the static class YetaWF.Core.IO.Module. The access methods provided in YetaWF.Core.IO.Module are for framework use only.

The module data provider can be configured using AppSettings.json. It uses the IOMode setting in the YetaWF_Core section. If none is specified, the Default section is used.

Possible IOMode settings are File, SQL or PostgreSQL. If SQL is specified, the SQLDbo and SQLConnect properties must be provided. If PostgreSQL is specified, the PostgreSQLSchema and PostgreSQLConnect properties must be provided.

{
  "Application": {
    "P": {
      "Default": {
        "IOMode": "File",
      },
      "YetaWF_Core": {
        "IOMode": "File"
      },
    },
  },
}
{
  "Application": {
    "P": {
      "Default": {
        "IOMode": "SQL",
        "SQLDbo": "dbo",
        "SQLConnect": "Data Source=..datasource..;Initial Catalog=..catalog..;User ID=..userid..;Password=..password.."
      },
      "YetaWF_Core": {
        "IOMode": "SQL",
        "SQLDbo": "dbo",
        "SQLConnect": "Data Source=..datasource..;Initial Catalog=..catalog..;User ID=..userid..;Password=..password.."
      },
    },
  },
}
{
  "Application": {
    "P": {
      "Default": {
        "IOMode": "PostgreSQL",
        "PostgreSQLSchema": "public",
        "PostgreSQLConnect": "Host=..host..;Port=..port..;Username=..user..;Password=..password..;Database=..database.."
      },
      "YetaWF_Core": {
        "IOMode": "PostgreSQL",
        "PostgreSQLSchema": "public",
        "PostgreSQLConnect": "Host=..host..;Port=..port..;Username=..user..;Password=..password..;Database=..database.."
      },
    },
  },
}

The module data provider is currently somewhat tightly integrated into YetaWF as modules use a template class in the module data provider to implement their own data provider. This may change at some time to make the module data provider completely replaceable (plug and play) like other low-level components in YetaWF.

Localization Data Providers

YetaWF provides a localization data provider that implements loading/saving localization resources.

Localization Data ProviderDescription
YetaWF.DataProvider.Localization PackageThe package supports loading/saving localization resources.

A localization data provider is a special type of data provider. It installs itself during application startup by providing access methods in the static class YetaWF.Core.IO.Localization. The access methods provided in YetaWF.Core.IO.Localization are for framework use only.