• ABP.Next系列02 项目下载 运行 -Fstyle


    系列文章目录

     ABP.Next系列02  7.3.0 aspnet-core 
    ABP.Next系列01-有啥?像啥?infrastructure -Fstyle_云草桑的博客-CSDN博客


    提示: 面试经常有项目经理巴拉巴拉 搭个API框架要多久。。。。若是以前 怎么都得几个月 现在net6了看看吧。

    文章目录


    前言

    提示:这里可以添加本文要记录的大概内容:


    提示:以下是本篇文章正文内容, 

    一、第一步 入口 下载代码 aspnetboilerplate.com

    Startup Templates - Create a Demo | AspNet Boilerplate

    二、下载完毕 Startup Templates

    1.使用步骤

    代码如下(示例):

    1. public class Startup
    2. {
    3. private const string _defaultCorsPolicyName = "localhost";
    4. private const string _apiVersion = "v1";
    5. private readonly IConfigurationRoot _appConfiguration;
    6. private readonly IWebHostEnvironment _hostingEnvironment;
    7. public Startup(IWebHostEnvironment env)
    8. {
    9. _hostingEnvironment = env;
    10. _appConfiguration = env.GetAppConfiguration();
    11. }
    12. public void ConfigureServices(IServiceCollection services)
    13. {
    14. //MVC
    15. services.AddControllersWithViews(
    16. options => { options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute()); }
    17. ).AddNewtonsoftJson(options =>
    18. {
    19. options.SerializerSettings.ContractResolver = new AbpMvcContractResolver(IocManager.Instance)
    20. {
    21. NamingStrategy = new CamelCaseNamingStrategy()
    22. };
    23. });
    24. IdentityRegistrar.Register(services);
    25. AuthConfigurer.Configure(services, _appConfiguration);
    26. services.AddSignalR();
    27. // Configure CORS for angular2 UI
    28. services.AddCors(
    29. options => options.AddPolicy(
    30. _defaultCorsPolicyName,
    31. builder => builder
    32. .WithOrigins(
    33. // App:CorsOrigins in appsettings.json can contain more than one address separated by comma.
    34. _appConfiguration["App:CorsOrigins"]
    35. .Split(",", StringSplitOptions.RemoveEmptyEntries)
    36. .Select(o => o.RemovePostFix("/"))
    37. .ToArray()
    38. )
    39. .AllowAnyHeader()
    40. .AllowAnyMethod()
    41. .AllowCredentials()
    42. )
    43. );
    44. // Swagger - Enable this line and the related lines in Configure method to enable swagger UI
    45. ConfigureSwagger(services);
    46. // Configure Abp and Dependency Injection
    47. services.AddAbpWithoutCreatingServiceProvider(
    48. // Configure Log4Net logging
    49. options => options.IocManager.IocContainer.AddFacility(
    50. f => f.UseAbpLog4Net().WithConfig(_hostingEnvironment.IsDevelopment()
    51. ? "log4net.config"
    52. : "log4net.Production.config"
    53. )
    54. )
    55. );
    56. }
    57. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
    58. {
    59. app.UseAbp(options => { options.UseAbpRequestLocalization = false; }); // Initializes ABP framework.
    60. app.UseCors(_defaultCorsPolicyName); // Enable CORS!
    61. app.UseStaticFiles();
    62. app.UseRouting();
    63. app.UseAuthentication();
    64. app.UseAbpRequestLocalization();
    65. app.UseEndpoints(endpoints =>
    66. {
    67. endpoints.MapHub("/signalr");
    68. endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
    69. endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}");
    70. });
    71. // Enable middleware to serve generated Swagger as a JSON endpoint
    72. app.UseSwagger(c => { c.RouteTemplate = "swagger/{documentName}/swagger.json"; });
    73. // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
    74. app.UseSwaggerUI(options =>
    75. {
    76. // specifying the Swagger JSON endpoint.
    77. options.SwaggerEndpoint($"/swagger/{_apiVersion}/swagger.json", $"cao919demo API {_apiVersion}");
    78. options.IndexStream = () => Assembly.GetExecutingAssembly()
    79. .GetManifestResourceStream("cao919demo.Web.Host.wwwroot.swagger.ui.index.html");
    80. options.DisplayRequestDuration(); // Controls the display of the request duration (in milliseconds) for "Try it out" requests.
    81. }); // URL: /swagger
    82. }
    83. private void ConfigureSwagger(IServiceCollection services)
    84. {
    85. services.AddSwaggerGen(options =>
    86. {
    87. options.SwaggerDoc(_apiVersion, new OpenApiInfo
    88. {
    89. Version = _apiVersion,
    90. Title = "cao919demo API",
    91. Description = "cao919demo",
    92. // uncomment if needed TermsOfService = new Uri("https://example.com/terms"),
    93. Contact = new OpenApiContact
    94. {
    95. Name = "cao919demo",
    96. Email = string.Empty,
    97. Url = new Uri("https://twitter.com/aspboilerplate"),
    98. },
    99. License = new OpenApiLicense
    100. {
    101. Name = "MIT License",
    102. Url = new Uri("https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/LICENSE"),
    103. }
    104. });
    105. options.DocInclusionPredicate((docName, description) => true);
    106. // Define the BearerAuth scheme that's in use
    107. options.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme()
    108. {
    109. Description =
    110. "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
    111. Name = "Authorization",
    112. In = ParameterLocation.Header,
    113. Type = SecuritySchemeType.ApiKey
    114. });
    115. //add summaries to swagger
    116. bool canShowSummaries = _appConfiguration.GetValue<bool>("Swagger:ShowSummaries");
    117. if (canShowSummaries)
    118. {
    119. var hostXmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
    120. var hostXmlPath = Path.Combine(AppContext.BaseDirectory, hostXmlFile);
    121. options.IncludeXmlComments(hostXmlPath);
    122. var applicationXml = $"cao919demo.Application.xml";
    123. var applicationXmlPath = Path.Combine(AppContext.BaseDirectory, applicationXml);
    124. options.IncludeXmlComments(applicationXmlPath);
    125. var webCoreXmlFile = $"cao919demo.Web.Core.xml";
    126. var webCoreXmlPath = Path.Combine(AppContext.BaseDirectory, webCoreXmlFile);
    127. options.IncludeXmlComments(webCoreXmlPath);
    128. }
    129. });
    130. }
    131. }

    继承web core

     
    

    2.Migrator日志迁移 

    基础设施层

     

    领域实体

    代码如下(示例):

    1. public class User : AbpUser<User>
    2. {
    3. public const string DefaultPassword = "123qwe";
    4. public static string CreateRandomPassword()
    5. {
    6. return Guid.NewGuid().ToString("N").Truncate(16);
    7. }
    8. public static User CreateTenantAdminUser(int tenantId, string emailAddress)
    9. {
    10. var user = new User
    11. {
    12. TenantId = tenantId,
    13. UserName = AdminUserName,
    14. Name = AdminUserName,
    15. Surname = AdminUserName,
    16. EmailAddress = emailAddress,
    17. Roles = new List()
    18. };
    19. user.SetNormalizedNames();
    20. return user;
    21. }
    22. }

    该处使用的url网络请求的数据。

    2.应用层

    3数据库链接

     
        "Default": "server=3 1,1433\\MS ;database=abpca oDbtest;uid= ;pwd= ; "

    4创建个类

    1. public class Persons :Entity
    2. {
    3. //Entity 里已有
    4. //public int Id { get; set; }
    5. public string name { get; set; }
    6. public int Age { get; set; }
    7. }

    5基础设施层

    添加表

    6常量定义

     

     7 EFcore 实体映射表

     命令 :Add Migrator i1

     注意选择项目 和迁移日志连接字符串

     先创建实例库

    https://blog.csdn.net/cao919/article/details/126535193

    Add-Migration

     Update-Database

    OK


    天气太热  电脑配置太低 丢 。VM都坏了。。。先到这里吧 

    总结

     以上就是今天要讲的内容, 

  • 相关阅读:
    基于SSH开发校园社团管理系统 课程设计 大作业 毕业设计
    C++多态之虚函数表详解及代码示例
    深入学习NumPy库在数据分析中的应用场景
    RabbitMQ初步到精通-第五章-RabbitMQ之消息防丢失
    数据库的主键和外键
    SQL语句优化、mysql不走索引的原因、数据库索引的设计原则
    新晋“学霸”夸克大模型拿下C-Eval和CMMLU双榜第一
    C语言模拟类的宏
    Node.js浅学
    让实时操作系统助力电力电子系统设计
  • 原文地址:https://blog.csdn.net/cao919/article/details/126526931