临河任务调度
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.2KB

  1. using System;
  2. using System.Net.Http;
  3. using Blazorise.Bootstrap5;
  4. using Blazorise.Icons.FontAwesome;
  5. using Microsoft.AspNetCore.Components.Web;
  6. using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.DependencyInjection;
  9. using Himp.TaskScheduling.Blazor.WebAssembly;
  10. using Volo.Abp.Account;
  11. using Volo.Abp.AspNetCore.Components.Web.Theming.Routing;
  12. using Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme;
  13. using Volo.Abp.Autofac.WebAssembly;
  14. using Volo.Abp.AutoMapper;
  15. using Volo.Abp.Identity.Blazor.WebAssembly;
  16. using Volo.Abp.Modularity;
  17. using Volo.Abp.SettingManagement.Blazor.WebAssembly;
  18. using Volo.Abp.TenantManagement.Blazor.WebAssembly;
  19. using Volo.Abp.UI.Navigation;
  20. namespace Himp.TaskScheduling.Blazor.Host.Client;
  21. [DependsOn(
  22. typeof(AbpAutofacWebAssemblyModule),
  23. typeof(AbpAspNetCoreComponentsWebAssemblyBasicThemeModule),
  24. typeof(AbpAccountApplicationContractsModule),
  25. typeof(AbpIdentityBlazorWebAssemblyModule),
  26. typeof(AbpTenantManagementBlazorWebAssemblyModule),
  27. typeof(AbpSettingManagementBlazorWebAssemblyModule),
  28. typeof(TaskSchedulingBlazorWebAssemblyModule)
  29. )]
  30. public class TaskSchedulingBlazorHostClientModule : AbpModule
  31. {
  32. public override void ConfigureServices(ServiceConfigurationContext context)
  33. {
  34. var environment = context.Services.GetSingletonInstance<IWebAssemblyHostEnvironment>();
  35. var builder = context.Services.GetSingletonInstance<WebAssemblyHostBuilder>();
  36. ConfigureAuthentication(builder);
  37. ConfigureHttpClient(context, environment);
  38. ConfigureBlazorise(context);
  39. ConfigureRouter(context);
  40. ConfigureMenu(context);
  41. ConfigureAutoMapper(context);
  42. }
  43. private void ConfigureRouter(ServiceConfigurationContext context)
  44. {
  45. Configure<AbpRouterOptions>(options =>
  46. {
  47. options.AppAssembly = typeof(TaskSchedulingBlazorHostClientModule).Assembly;
  48. });
  49. }
  50. private void ConfigureMenu(ServiceConfigurationContext context)
  51. {
  52. Configure<AbpNavigationOptions>(options =>
  53. {
  54. options.MenuContributors.Add(new TaskSchedulingHostMenuContributor(context.Services.GetConfiguration()));
  55. });
  56. }
  57. private void ConfigureBlazorise(ServiceConfigurationContext context)
  58. {
  59. context.Services
  60. .AddBootstrap5Providers()
  61. .AddFontAwesomeIcons();
  62. }
  63. private static void ConfigureAuthentication(WebAssemblyHostBuilder builder)
  64. {
  65. builder.Services.AddOidcAuthentication(options =>
  66. {
  67. builder.Configuration.Bind("AuthServer", options.ProviderOptions);
  68. options.ProviderOptions.DefaultScopes.Add("TaskScheduling");
  69. });
  70. }
  71. private static void ConfigureHttpClient(ServiceConfigurationContext context, IWebAssemblyHostEnvironment environment)
  72. {
  73. context.Services.AddTransient(sp => new HttpClient
  74. {
  75. BaseAddress = new Uri(environment.BaseAddress)
  76. });
  77. }
  78. private void ConfigureAutoMapper(ServiceConfigurationContext context)
  79. {
  80. Configure<AbpAutoMapperOptions>(options =>
  81. {
  82. options.AddMaps<TaskSchedulingBlazorHostClientModule>();
  83. });
  84. }
  85. }