首页
/ 开源项目 `clean-code-dotnet` 使用教程

开源项目 `clean-code-dotnet` 使用教程

2024-08-23 12:54:04作者:董灵辛Dennis

1. 项目的目录结构及介绍

clean-code-dotnet 项目的目录结构如下:

clean-code-dotnet/
├── .github/
│   └── workflows/
├── src/
│   ├── Clean.Architecture.Sample/
│   ├── Clean.Architecture.Tests/
│   └── ...
├── .gitignore
├── .editorconfig
├── README.md
└── ...

目录结构介绍

  • .github/workflows/: 包含 GitHub Actions 的工作流配置文件。
  • src/: 包含项目的源代码,包括示例项目和测试项目。
    • Clean.Architecture.Sample/: 示例项目的源代码。
    • Clean.Architecture.Tests/: 测试项目的源代码。
  • .gitignore: Git 忽略文件配置。
  • .editorconfig: 编辑器配置文件,用于统一代码风格。
  • README.md: 项目说明文档。

2. 项目的启动文件介绍

项目的启动文件位于 src/Clean.Architecture.Sample/ 目录下,主要文件包括:

  • Program.cs: 应用程序的入口点,包含 Main 方法。
  • Startup.cs: 配置服务和应用程序的请求管道。

Program.cs

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace Clean.Architecture.Sample
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}

Startup.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Clean.Architecture.Sample
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}

3. 项目的配置文件介绍

项目的配置文件主要包括 appsettings.jsonappsettings.Development.json

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

appsettings.Development.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

配置文件介绍

  • Logging: 配置日志级别。
  • AllowedHosts: 配置允许访问的主机。

以上是 clean-code-dotnet 项目的基本使用教程,涵盖了项目的目录结构、启动文件和配置文件的介绍。希望对您有所帮助!

登录后查看全文
热门项目推荐
相关项目推荐

项目优选

收起
kernelkernel
deepin linux kernel
C
24
7
nop-entropynop-entropy
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
9
1
Cangjie-ExamplesCangjie-Examples
本仓将收集和展示高质量的仓颉示例代码,欢迎大家投稿,让全世界看到您的妙趣设计,也让更多人通过您的编码理解和喜爱仓颉语言。
Cangjie
375
3.25 K
flutter_flutterflutter_flutter
暂无简介
Dart
619
140
leetcodeleetcode
🔥LeetCode solutions in any programming language | 多种编程语言实现 LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解
Java
62
19
openHiTLSopenHiTLS
旨在打造算法先进、性能卓越、高效敏捷、安全可靠的密码套件,通过轻量级、可剪裁的软件技术架构满足各行业不同场景的多样化要求,让密码技术应用更简单,同时探索后量子等先进算法创新实践,构建密码前沿技术底座!
C
1.03 K
479
ops-mathops-math
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
647
261
RuoYi-Vue3RuoYi-Vue3
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
1.09 K
619
giteagitea
喝着茶写代码!最易用的自托管一站式代码托管平台,包含Git托管,代码审查,团队协作,软件包和CI/CD。
Go
23
0
cherry-studiocherry-studio
🍒 Cherry Studio 是一款支持多个 LLM 提供商的桌面客户端
TypeScript
790
76