Integrate DevExpress Web Dashboard into API and Blazor
Added DevExpress Dashboard to ASP.NET Core API and both Blazor WASM/Server frontends. Configured dashboard storage, sample data source, and API endpoint. Updated Blazor projects with dashboard packages, styles, and a new dashboard page. Navigation and configuration updated to support dashboard integration.
This commit is contained in:
14
DbFirst.API/Controllers/DefaultDashboardController.cs
Normal file
14
DbFirst.API/Controllers/DefaultDashboardController.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using DevExpress.DashboardAspNetCore;
|
||||
using DevExpress.DashboardWeb;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
|
||||
namespace BlazorDashboardApp.Server
|
||||
{
|
||||
public class DefaultDashboardController : DashboardController
|
||||
{
|
||||
public DefaultDashboardController(DashboardConfigurator configurator, IDataProtectionProvider? dataProtectionProvider = null)
|
||||
: base(configurator, dataProtectionProvider)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
4
DbFirst.API/Data/Dashboards/DefaultDashboard.xml
Normal file
4
DbFirst.API/Data/Dashboards/DefaultDashboard.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Dashboard CurrencyCulture="de-DE" RequestParameters="false">
|
||||
<Title Text="Default Dashboard" />
|
||||
</Dashboard>
|
||||
@@ -9,6 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="12.0.1" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||
<PackageReference Include="DevExpress.AspNetCore.Dashboard" Version="25.2.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.22" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.22" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.22">
|
||||
@@ -25,4 +26,8 @@
|
||||
<ProjectReference Include="..\DbFirst.Infrastructure\DbFirst.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Data\Dashboards\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -4,6 +4,11 @@ using DbFirst.Application.Repositories;
|
||||
using DbFirst.Domain;
|
||||
using DbFirst.Infrastructure;
|
||||
using DbFirst.Infrastructure.Repositories;
|
||||
using DevExpress.AspNetCore;
|
||||
using DevExpress.DashboardAspNetCore;
|
||||
using DevExpress.DashboardCommon;
|
||||
using DevExpress.DashboardWeb;
|
||||
using DevExpress.DataAccess.Json;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -44,6 +49,33 @@ builder.Services.AddApplication();
|
||||
|
||||
builder.Services.AddScoped<ICatalogRepository, CatalogRepository>();
|
||||
|
||||
builder.Services.AddDevExpressControls();
|
||||
builder.Services.AddScoped<DashboardConfigurator>((IServiceProvider serviceProvider) => {
|
||||
var dashboardsPath = Path.Combine(builder.Environment.ContentRootPath, "Data", "Dashboards");
|
||||
Directory.CreateDirectory(dashboardsPath);
|
||||
|
||||
var defaultDashboardPath = Path.Combine(dashboardsPath, "DefaultDashboard.xml");
|
||||
if (!File.Exists(defaultDashboardPath))
|
||||
{
|
||||
var defaultDashboard = new Dashboard();
|
||||
defaultDashboard.Title.Text = "Default Dashboard";
|
||||
defaultDashboard.SaveToXml(defaultDashboardPath);
|
||||
}
|
||||
|
||||
DashboardConfigurator configurator = new DashboardConfigurator();
|
||||
// Register Dashboard Storage
|
||||
configurator.SetDashboardStorage(new DashboardFileStorage(dashboardsPath));
|
||||
// Create a sample JSON data source
|
||||
DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
|
||||
DashboardJsonDataSource jsonDataSourceUrl = new DashboardJsonDataSource("JSON Data Source (URL)");
|
||||
jsonDataSourceUrl.JsonSource = new UriJsonSource(
|
||||
new Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"));
|
||||
jsonDataSourceUrl.RootElement = "Customers";
|
||||
dataSourceStorage.RegisterDataSource("jsonDataSourceUrl", jsonDataSourceUrl.SaveToXml());
|
||||
configurator.SetDataSourceStorage(dataSourceStorage);
|
||||
return configurator;
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
@@ -55,10 +87,13 @@ if (app.Environment.IsDevelopment())
|
||||
|
||||
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
||||
|
||||
app.UseDevExpressControls();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseCors();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapDashboardRoute("api/dashboard", "DefaultDashboard");
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user