diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj index 00d344b49e..79fdb16b71 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -13,7 +13,9 @@ - + + + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs index 56b24bbbdb..5dd8da4502 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs @@ -2,10 +2,19 @@ using System.Net.Http; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Autofac; +using Volo.Abp.Http.Client; +using Volo.Abp.Http.Client.IdentityModel; +using Volo.Abp.IdentityModel; using Volo.Abp.Modularity; namespace MyCompanyName.MyProjectName.Blazor { + [DependsOn( + typeof(AbpAutofacModule), + typeof(MyProjectNameHttpApiClientModule), + typeof(AbpHttpClientIdentityModelModule) + )] public class MyProjectNameBlazorModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) @@ -13,12 +22,47 @@ namespace MyCompanyName.MyProjectName.Blazor var environment = context.Services.GetSingletonInstance(); var builder = context.Services.GetSingletonInstance(); - context.Services.AddTransient(sp => new HttpClient + ConfigureAuthentication(context); + ConfigureRemoteServices(context); + ConfigureHttpClient(context, environment); + ConfigureUI(builder); + } + + private void ConfigureAuthentication(ServiceConfigurationContext context) + { + context.Services.Configure(options => { - BaseAddress = new Uri(environment.BaseAddress) + //TODO: Get from config, automatically! + options.IdentityClients.Default.Authority = "https://localhost:44305"; + options.IdentityClients.Default.GrantType = "password"; + options.IdentityClients.Default.ClientId = "MyProjectName_App"; + options.IdentityClients.Default.ClientSecret = "1q2w3e*"; + options.IdentityClients.Default.UserName = "admin"; + options.IdentityClients.Default.UserPassword = "1q2w3E*"; + options.IdentityClients.Default.Scope = "MyProjectName"; }); + } + private void ConfigureRemoteServices(ServiceConfigurationContext context) + { + //TODO: Get from config, automatically! + Configure(options => + { + options.RemoteServices.Default.BaseUrl = "https://localhost:44305"; + }); + } + + private static void ConfigureUI(WebAssemblyHostBuilder builder) + { builder.RootComponents.Add("app"); } + + private static void ConfigureHttpClient(ServiceConfigurationContext context, IWebAssemblyHostEnvironment environment) + { + context.Services.AddTransient(sp => new HttpClient + { + BaseAddress = new Uri(environment.BaseAddress) + }); + } } } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyService.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyService.cs new file mode 100644 index 0000000000..1c106fb378 --- /dev/null +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyService.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Identity; + +namespace MyCompanyName.MyProjectName.Blazor +{ + public class MyProfileService : ITransientDependency + { + private readonly IProfileAppService _profileAppService; + + public MyProfileService(IProfileAppService profileAppService) + { + _profileAppService = profileAppService; + } + + public async Task GetUserNameAsync() + { + return "test"; + } + } +} diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Program.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Program.cs index 2590d401c2..b96ae9b888 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Program.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Program.cs @@ -1,7 +1,10 @@ using System.Threading.Tasks; +using Autofac; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.Autofac; namespace MyCompanyName.MyProjectName.Blazor { @@ -11,11 +14,16 @@ namespace MyCompanyName.MyProjectName.Blazor { var builder = WebAssemblyHostBuilder.CreateDefault(args); - //Should be done in the ABP framework! + //TODO: Should be done in the ABP framework! builder.Services.AddSingleton(builder.Configuration); builder.Services.AddSingleton(builder); - builder.Services.AddApplication(); + builder.Services.AddApplication(opts => + { + opts.UseAutofac(); + }); + + builder.ConfigureContainer(builder.Services.GetSingletonInstance>()); await builder.Build().RunAsync(); }