Prepare Data Source Storage
- 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 storage
- Create 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 storage
- Implement 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
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
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);
}
}
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 Core | ASP.NET MVC |
---|---|
SQL | SQL |
OLAP | OLAP |
Excel | Excel |
Object | Object |
Entity Framework | Entity Framework |
Data Extract | Data Extract |
JSON | JSON |
XPO | XPO |
MongoDB | MongoDB |
Data Federation | Data 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 andWeb.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.
Example
The example shows how to make a set of data sources available for users in the Web Dashboard application.