ABP.Next系列02 7.3.0 aspnet-core
ABP.Next系列01-有啥?像啥?infrastructure -Fstyle_云草桑的博客-CSDN博客
提示: 面试经常有项目经理巴拉巴拉 搭个API框架要多久。。。。若是以前 怎么都得几个月 现在net6了看看吧。
提示:这里可以添加本文要记录的大概内容:
提示:以下是本篇文章正文内容,
Startup Templates - Create a Demo | AspNet Boilerplate
代码如下(示例):
public class Startup { private const string _defaultCorsPolicyName = "localhost"; private const string _apiVersion = "v1"; private readonly IConfigurationRoot _appConfiguration; private readonly IWebHostEnvironment _hostingEnvironment; public Startup(IWebHostEnvironment env) { _hostingEnvironment = env; _appConfiguration = env.GetAppConfiguration(); } public void ConfigureServices(IServiceCollection services) { //MVC services.AddControllersWithViews( options => { options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute()); } ).AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new AbpMvcContractResolver(IocManager.Instance) { NamingStrategy = new CamelCaseNamingStrategy() }; }); IdentityRegistrar.Register(services); AuthConfigurer.Configure(services, _appConfiguration); services.AddSignalR(); // Configure CORS for angular2 UI services.AddCors( options => options.AddPolicy( _defaultCorsPolicyName, builder => builder .WithOrigins( // App:CorsOrigins in appsettings.json can contain more than one address separated by comma. _appConfiguration["App:CorsOrigins"] .Split(",", StringSplitOptions.RemoveEmptyEntries) .Select(o => o.RemovePostFix("/")) .ToArray() ) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials() ) ); // Swagger - Enable this line and the related lines in Configure method to enable swagger UI ConfigureSwagger(services); // Configure Abp and Dependency Injection services.AddAbpWithoutCreatingServiceProvider( // Configure Log4Net logging options => options.IocManager.IocContainer.AddFacility( f => f.UseAbpLog4Net().WithConfig(_hostingEnvironment.IsDevelopment() ? "log4net.config" : "log4net.Production.config" ) ) ); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { app.UseAbp(options => { options.UseAbpRequestLocalization = false; }); // Initializes ABP framework. app.UseCors(_defaultCorsPolicyName); // Enable CORS! app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAbpRequestLocalization(); app.UseEndpoints(endpoints => { endpoints.MapHub("/signalr"); endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}"); }); // Enable middleware to serve generated Swagger as a JSON endpoint app.UseSwagger(c => { c.RouteTemplate = "swagger/{documentName}/swagger.json"; }); // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.) app.UseSwaggerUI(options => { // specifying the Swagger JSON endpoint. options.SwaggerEndpoint($"/swagger/{_apiVersion}/swagger.json", $"cao919demo API {_apiVersion}"); options.IndexStream = () => Assembly.GetExecutingAssembly() .GetManifestResourceStream("cao919demo.Web.Host.wwwroot.swagger.ui.index.html"); options.DisplayRequestDuration(); // Controls the display of the request duration (in milliseconds) for "Try it out" requests. }); // URL: /swagger } private void ConfigureSwagger(IServiceCollection services) { services.AddSwaggerGen(options => { options.SwaggerDoc(_apiVersion, new OpenApiInfo { Version = _apiVersion, Title = "cao919demo API", Description = "cao919demo", // uncomment if needed TermsOfService = new Uri("https://example.com/terms"), Contact = new OpenApiContact { Name = "cao919demo", Email = string.Empty, Url = new Uri("https://twitter.com/aspboilerplate"), }, License = new OpenApiLicense { Name = "MIT License", Url = new Uri("https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/LICENSE"), } }); options.DocInclusionPredicate((docName, description) => true); // Define the BearerAuth scheme that's in use options.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme() { Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }); //add summaries to swagger bool canShowSummaries = _appConfiguration.GetValue<bool>("Swagger:ShowSummaries"); if (canShowSummaries) { var hostXmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var hostXmlPath = Path.Combine(AppContext.BaseDirectory, hostXmlFile); options.IncludeXmlComments(hostXmlPath); var applicationXml = $"cao919demo.Application.xml"; var applicationXmlPath = Path.Combine(AppContext.BaseDirectory, applicationXml); options.IncludeXmlComments(applicationXmlPath); var webCoreXmlFile = $"cao919demo.Web.Core.xml"; var webCoreXmlPath = Path.Combine(AppContext.BaseDirectory, webCoreXmlFile); options.IncludeXmlComments(webCoreXmlPath); } }); } }
继承web core
基础设施层
领域实体
代码如下(示例):
- public class User : AbpUser<User>
- {
- public const string DefaultPassword = "123qwe";
-
- public static string CreateRandomPassword()
- {
- return Guid.NewGuid().ToString("N").Truncate(16);
- }
-
- public static User CreateTenantAdminUser(int tenantId, string emailAddress)
- {
- var user = new User
- {
- TenantId = tenantId,
- UserName = AdminUserName,
- Name = AdminUserName,
- Surname = AdminUserName,
- EmailAddress = emailAddress,
- Roles = new List
() - };
-
- user.SetNormalizedNames();
-
- return user;
- }
- }
该处使用的url网络请求的数据。
2.应用层
3数据库链接
"Default": "server=3 1,1433\\MS ;database=abpca oDbtest;uid= ;pwd= ; "
4创建个类
- public class Persons :Entity
- {
-
- //Entity 里已有
- //public int Id { get; set; }
-
- public string name { get; set; }
- public int Age { get; set; }
-
- }
5基础设施层
添加表
6常量定义
7 EFcore 实体映射表
命令 :Add Migrator i1
注意选择项目 和迁移日志连接字符串
先创建实例库
https://blog.csdn.net/cao919/article/details/126535193
Add-Migration
Update-Database
OK
天气太热 电脑配置太低 丢 。VM都坏了。。。先到这里吧
以上就是今天要讲的内容,