This example shows a .NET Aspire Dashboard integrated into an ASP.NET Core Document Viewer application.
Prerequisites
To work with .NET Aspire, you need the following:
- .NET 8.0 or .NET 9.0
- .NET Aspire SDK
- Visual Studio 2022 version 17.9+
- .NET Aspire Dashboard application. Refer to the following help topic for information on how to create the application: Quick Start: Build your first .NET Aspire solution
- DevExpress Reports-powered application. Refer to the following section for tutorials on how to create an ASP.NET Core Report Viewer: Use Reporting Components
Add DevExpress NuGet Packages
Reference the following NuGet packages in your Reporting application:
DevExpress.Aspire.Reporting
DevExpress.Aspire.AspNetCore.Reporting
Implementation Details
- Add the following project references:
Project Reference AppHost/Orchestration project (usually with an *.AppHost suffix) DevExpress Reports application DevExpress Reports application ServiceDefaults application - Open your reporting project. Add the following method calls to
Program.cs
:C#var builder = WebApplication.CreateBuilder(args); builder.Services.AddDevExpressControls(); // Important note: Enable .NET Aspire integration after an AddDevExpressControls method call // Enable service discovery and configure OpenTelemetry metrics and tracing for .NET Aspire. // Learn more at: https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/service-defaults builder.AddServiceDefaults(); // Share trace data with the .NET Aspire Dashboard from DevExpress Reports document creation and exporting builder.AddReporting(); // Share trace and metrics data with the .NET Aspire Dashboard for the DevExpress Reports back end services builder.AddAspNetCoreReporting();
- Navigate to the
AppHost
project. Add the following project reference code toProgram.cs
:C#var builder = DistributedApplication.CreateBuilder(args); builder.AddProject<Projects.DevExpressReportingApp>("webreporting") .WithExternalHttpEndpoints(); builder.Build().Run();
- Build and run the *.AppHost solution to view output in the .NET Aspire dashboard.
Files to Review
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using DevExpress.AspNetCore;
using DevExpress.AspNetCore.Reporting;
using DevExpress.Security.Resources;
using DevExpress.XtraReports.Web.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using DevExpressReportingApp.Services;
using DevExpressReportingApp.Data;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDevExpressControls();
builder.AddServiceDefaults();
builder.AddReporting();
builder.AddAspNetCoreReporting();
builder.Services.AddScoped<ReportStorageWebExtension, CustomReportStorageWebExtension>();
builder.Services.AddMvc();
builder.Services.ConfigureReportingServices(configurator => {
if(builder.Environment.IsDevelopment()) {
configurator.UseDevelopmentMode();
}
configurator.ConfigureReportDesigner(designerConfigurator => {
designerConfigurator.RegisterDataSourceWizardConnectionStringsProvider<CustomSqlDataSourceWizardConnectionStringsProvider>();
designerConfigurator.RegisterDataSourceWizardJsonConnectionStorage<CustomDataSourceWizardJsonDataConnectionStorage>(true);
});
configurator.ConfigureWebDocumentViewer(viewerConfigurator => {
viewerConfigurator.UseCachedReportSourceBuilder();
viewerConfigurator.RegisterJsonDataConnectionProviderFactory<CustomJsonDataConnectionProviderFactory>();
viewerConfigurator.RegisterConnectionProviderFactory<CustomSqlDataConnectionProviderFactory>();
});
});
builder.Services.AddDbContext<ReportDbContext>(options => options.UseSqlite(builder.Configuration.GetConnectionString("ReportsDataConnectionString")));
var app = builder.Build();
using(var scope = app.Services.CreateScope()) {
var services = scope.ServiceProvider;
services.GetService<ReportDbContext>().InitializeDatabase();
}
var contentDirectoryAllowRule = DirectoryAccessRule.Allow(new DirectoryInfo(Path.Combine(builder.Environment.ContentRootPath, "Content")).FullName);
AccessSettings.ReportingSpecificResources.TrySetRules(contentDirectoryAllowRule, UrlAccessRule.Allow());
DevExpress.XtraReports.Configuration.Settings.Default.UserDesignerOptions.DataBindingMode = DevExpress.XtraReports.UI.DataBindingMode.Expressions;
app.UseDevExpressControls();
System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;
if(app.Environment.IsDevelopment()) {
app.UseDeveloperExceptionPage();
} else {
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
C#var builder = DistributedApplication.CreateBuilder(args);
var apiService = builder.AddProject<Projects.AspireStarterApp_ApiService>("apiservice");
builder.AddProject<Projects.AspireStarterApp_Web>("webfrontend")
.WithExternalHttpEndpoints()
.WithReference(apiService);
builder.AddProject<Projects.DevExpressReportingApp>("webreporting")
.WithExternalHttpEndpoints();
builder.Build().Run();