|
| 1 | +using DevExpress.AspNetCore; |
| 2 | +using DevExpress.DashboardAspNetCore; |
| 3 | +using DevExpress.DashboardWeb; |
| 4 | +using Microsoft.AspNetCore.Builder; |
| 5 | +using Microsoft.AspNetCore.Hosting; |
| 6 | +using Microsoft.Extensions.Configuration; |
| 7 | +using Microsoft.Extensions.DependencyInjection; |
| 8 | +using Microsoft.Extensions.FileProviders; |
| 9 | +using Microsoft.Extensions.Hosting; |
| 10 | + |
| 11 | +namespace WebDashboardAspNetCore3 { |
| 12 | + public class Startup { |
| 13 | + public Startup(IConfiguration configuration, IWebHostEnvironment hostingEnvironment) { |
| 14 | + Configuration = configuration; |
| 15 | + FileProvider = hostingEnvironment.ContentRootFileProvider; |
| 16 | + } |
| 17 | + |
| 18 | + public IConfiguration Configuration { get; } |
| 19 | + public IFileProvider FileProvider { get; } |
| 20 | + |
| 21 | + // This method gets called by the runtime. Use this method to add services to the container. |
| 22 | + public void ConfigureServices(IServiceCollection services) { |
| 23 | + services |
| 24 | + .AddDevExpressControls() |
| 25 | + .AddControllersWithViews() |
| 26 | + .AddDefaultDashboardController(configurator => { |
| 27 | + configurator.SetDashboardStorage(new DashboardFileStorage(FileProvider.GetFileInfo("Data/Dashboards").PhysicalPath)); |
| 28 | + configurator.SetConnectionStringsProvider(new DashboardConnectionStringsProvider(Configuration)); |
| 29 | + }); |
| 30 | + } |
| 31 | + |
| 32 | + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
| 33 | + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { |
| 34 | + if(env.IsDevelopment()) { |
| 35 | + app.UseDeveloperExceptionPage(); |
| 36 | + } else { |
| 37 | + app.UseExceptionHandler("/Home/Error"); |
| 38 | + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. |
| 39 | + app.UseHsts(); |
| 40 | + } |
| 41 | + app.UseHttpsRedirection(); |
| 42 | + app.UseStaticFiles(); |
| 43 | + app.UseDevExpressControls(); |
| 44 | + app.UseRouting(); |
| 45 | + app.UseAuthorization(); |
| 46 | + app.UseEndpoints(endpoints => { |
| 47 | + EndpointRouteBuilderExtension.MapDashboardRoute(endpoints, "api/dashboards"); |
| 48 | + endpoints.MapControllerRoute( |
| 49 | + name: "default", |
| 50 | + pattern: "{controller=Home}/{action=Index}/{id?}"); |
| 51 | + }); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments