Back to Devexpress

Prepare Data Source Storage

dashboard-116482-web-dashboard-integrate-dashboard-component-dashboard-backend-prepare-data-source-storage.md

latest9.9 KB
Original Source

Prepare Data Source Storage

  • Oct 18, 2024
  • 3 minutes to read

The Dashboard Configurator requires you to configure data source storage to supply users with a set of default data sources.

Create Data Source Storage

Data source storage is a location of settings used to connect the Web Dashboard to data sources. When you register a data source in the storage, you make this data source available for users. You can create one of the following storages:

Predefined storageCreate a DataSourceInMemoryStorage instance as the predefined implementation of an in-memory data source storage. Call the DataSourceInMemoryStorage.RegisterDataSource method to register the specified data source in the current storage.Custom storageImplement the IDataSourceStorage interface to create a custom data source storage. You can find one of the implementations in the following topic: Manage Multi-Tenancy.

To register the storage for a Web Dashboard, call the DashboardConfigurator.SetDataSourceStorage method and pass the storage you created as the method’s parameter.

ASP.NET Core

cs
using DevExpress.DashboardWeb;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDevExpressControls();
builder.Services.AddScoped<DashboardConfigurator>((IServiceProvider serviceProvider) => {
    DashboardConfigurator configurator = new DashboardConfigurator();
    // ...
    // Create and configure a data source storage.
    DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();

    DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source");
    objDataSource.DataId = "objectDataSource";
    dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml());

    configurator.SetDataSourceStorage(dataSourceStorage);

    return configurator;
});

var app = builder.Build();

ASP. NET MVC

csharp
public static class DashboardConfig {
    public static void RegisterService(RouteCollection routes) {
        routes.MapDashboardRoute("dashboardControl", "DefaultDashboard");

        // Configure a data source storage:
        DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();

        // Registers an Object data source.
        DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source");
        objDataSource.DataId = "objectDataSource";
        dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml());

        DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage);
    }
}
vb
Public Module DashboardConfig
    Public Sub RegisterService(ByVal routes As RouteCollection)
        routes.MapDashboardRoute("dashboardControl", "DefaultDashboard")

        ' Configure a data source storage:
        Dim dataSourceStorage As New DataSourceInMemoryStorage()

        ' Registers an Object data source.
        Dim objDataSource As New DashboardObjectDataSource("Object Data Source")
        objDataSource.DataId = "objectDataSource"
        dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml())

        DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage)
    End Sub
End Module

Register Data Sources

The Web Dashboard supports a wide variety of data sources. Open the article about a specific data source for configuration details:

ASP.NET CoreASP.NET MVC
SQLSQL
OLAPOLAP
ExcelExcel
ObjectObject
Entity FrameworkEntity Framework
Data ExtractData Extract
JSONJSON
XPOXPO
MongoDBMongoDB
Data FederationData Federation

Tip

Make sure you add the configured data sources to the data storage you use in the Web Dashboard.

Protect User Data

The Web Dashboard saves user credentials used by data sources to the dashboard XML definition.

Use the DashboardConfigurator.PassCredentials property to specify whether to pass this information to the client side (web browser). Set this property to false and specify connection parameters in one of the following ways to avoid any security issues:

Specify connection parameters in appsettings.json / Web.config Add a connection string to the connectionStrings section in the configuration file (appsettings.json for ASP.NET Core and Web.config for ASP.NET MVC).Create a data connections provider Implement the IDataSourceWizardConnectionStringsProvider interface to create a data connections provider. Pass the created provider as the DashboardConfigurator.SetConnectionStringsProvider method’s parameter.Specify the connection parameters at runtime Handle the DashboardConfigurator.ConfigureDataConnection event to specify the connection parameters at runtime.

The following examples configure the Dashboard control so that it loads data based on the current user. You can identify a user in the current session and handle the events to select the underlying data source.

View Example: ASP.NET CoreView Example: ASP.NET MVC

Example

The example shows how to make a set of data sources available for users in the Web Dashboard application.

View Example: ASP.NET CoreView Example: ASP.NET MVC