ABP微服务系列学习-搭建自己的微服务结构(三) 痛定思痛。 2023-09-24 21:28 45阅读 0赞 上一篇我们基础服务初步搭建完毕,接下来我们整一下认证和网关。 ### 搭建认证服务[\#][Link 1] ### 认证服务的话,ABP CLI生成的所有模板都包括了一个AuthServer。我们直接生成模板然后微调一下就可以直接用了。 abp new FunShow -t app --tiered 使用命令创建模板后,我们可以找到一个AuthServer。把项目移动到Apps目录下,然后我们开始改造一下这个项目。 首先修改项目文件的引用配置 修改EFCore项目引用为AdministrationService.EntityFrameworkCore和IdentityService.EntityFrameworkCore, 然后添加Shared.Localization和Shared.Hosting.AspNetCore项目引用,别的基本不用怎么修改,完整项目配置为: <Project Sdk="Microsoft.NET.Sdk.Web"> <Import Project="..\..\..\..\common.props" /> <PropertyGroup> <TargetFramework>net7.0</TargetFramework> <UserSecretsId>b83bc18b-a6ca-4e2d-a827-26ffaff35dce</UserSecretsId> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerfileContext>..\..\..\..</DockerfileContext> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.5" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" /> </ItemGroup> <ItemGroup> <PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="7.0.0" /> <PackageReference Include="Volo.Abp.EventBus.RabbitMQ" Version="7.0.0" /> <PackageReference Include="Volo.Abp.BackgroundJobs.RabbitMQ" Version="7.0.0" /> <PackageReference Include="Volo.Abp.Account.Web.OpenIddict" Version="7.0.0" /> <PackageReference Include="Volo.Abp.Account.Application" Version="7.0.0" /> <PackageReference Include="Volo.Abp.Account.HttpApi" Version="7.0.0" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\..\..\services\administration\src\FunShow.AdministrationService.EntityFrameworkCore\FunShow.AdministrationService.EntityFrameworkCore.csproj" /> <ProjectReference Include="..\..\..\..\services\identity\src\FunShow.IdentityService.EntityFrameworkCore\FunShow.IdentityService.EntityFrameworkCore.csproj" /> <ProjectReference Include="..\..\..\..\shared\FunShow.Shared.Hosting.AspNetCore\FunShow.Shared.Hosting.AspNetCore.csproj" /> <ProjectReference Include="..\..\..\..\shared\FunShow.Shared.Localization\FunShow.Shared.Localization.csproj" /> </ItemGroup> <ItemGroup> <PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite" Version="2.0.0-*" /> </ItemGroup> <ItemGroup> <Compile Remove="Logs\**" /> <Content Remove="Logs\**" /> <EmbeddedResource Remove="Logs\**" /> <None Remove="Logs\**" /> </ItemGroup> </Project> 然后修改Program文件,主要是日志配置修改一下,别的不用改动 using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using FunShow.Shared.Hosting.AspNetCore; using Serilog; namespace FunShow.AuthServer; public class Program { public async static Task<int> Main(string[] args) { var assemblyName = typeof(Program).Assembly.GetName().Name; SerilogConfigurationHelper.Configure(assemblyName); try { Log.Information($"Starting {assemblyName}."); var builder = WebApplication.CreateBuilder(args); builder.Host .AddAppSettingsSecretsJson() .UseAutofac() .UseSerilog(); await builder.AddApplicationAsync<FunShowAuthServerModule>(); var app = builder.Build(); await app.InitializeApplicationAsync(); await app.RunAsync(); return 0; } catch (Exception ex) { Log.Fatal(ex, $"{assemblyName} terminated unexpectedly!"); return 1; } finally { Log.CloseAndFlush(); } } } 修改module.cs using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using FunShow.AdministrationService.EntityFrame [Link 1]: https://www.cnblogs.com/fanshaoO/p/17166952.html#%E6%90%AD%E5%BB%BA%E8%AE%A4%E8%AF%81%E6%9C%8D%E5%8A%A1
还没有评论,来说两句吧...