Skip to content

ASP.NET Core 是一个跨平台的高性能开源框架,用于生成基于云且连接 Internet 的新式应用程序。 可用于建立Web应用、 IoT物联网、移动后端等。

Notifications You must be signed in to change notification settings

angenal/AspNetCore

Repository files navigation

ASP.NET Core 是一个跨平台的高性能开源框架,用于生成基于云且连接 Internet 的新式应用程序。
可用于建立Web应用、 IoT物联网、移动后端等。

CLI命令行

#! 安装工具
   dotnet tool install -g csharprepl # csharp console playground
   dotnet tool install -g dotnet-ef  # dotnet ef database-migrations tool
   dotnet tool install -g dotnet-trace # 监控.NET程序的GC; 获取所有进程: dotnet trace ps 诊断指定程序: dotnet gcmon -p 1024

#! 安装模板,创建项目
   dotnet new console                # Common/Console
   dotnet new classlib               # Common/Library
   dotnet new web                    # Web/Empty
   dotnet new webapi                 # Web/WebAPI
   dotnet new mvc                    # Web/MVC
   dotnet new sln                    # Solution
   dotnet new globaljson             # Config
   dotnet new nugetconfig            # Config
   dotnet new webconfig              # Config
   dotnet new --install Microsoft.AspNetCore.SpaTemplates::* # install templates from official repository
   dotnet new angular                # 创建新的项目使用 SPA 模板
   dotnet new react                  # Web/MVC/SPA
   dotnet new reactredux             # Web/MVC/SPA
   dotnet new --install [path-to-repository] # install templates from src (exists *dotnet-templates.nuspec)
   dotnet new avalonia.app           # ui/xaml from https://github.com/AvaloniaUI/avalonia-dotnet-templates
   dotnet new avalonia.mvvm          # ui/xaml
   dotnet new avalonia.usercontrol   # ui/xaml
   dotnet new avalonia.window        # ui/xaml
   dotnet new avalonia.resource      # ui/xaml
   dotnet new avalonia.styles        # ui/xaml
   ... ...                           # dotnet new --help
# <PM> 从数据库至代码MODEL / DbFirst
PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer
PM> Install-Package Microsoft.EntityFrameworkCore.Tools
# 脚手架工具Scaffold 用于生成模板代码
# Scaffold-DbContext {ConnectionString} Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models/Entities -Context {DbName}DbContext -ContextDir Models -DataAnnotations -Force
PM> Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=DbName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

# <PM> 从代码MODEL至数据库,名称“Initial”是任意的,用于对迁移文件进行命名  / CodeFirst
PM> Add-Migration Initial    # 添加迁移版本的名称
PM> Update-Database          # 迁移至数据库
PS> dotnet ef migrations -h  # 使用命令行CMD或PowerShell
PS> dotnet ef migrations add Initial
PS> dotnet ef database update

# <PM> WEB页面与代码生成器
PM> Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design -Version 2.0.3
PM> dotnet aspnet-codegenerator razorpage -m Movie -dc MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries

# <PM> Desktop桌面跨平台应用
PM> Install-Package Avalonia            # ui/xaml from https://github.com/AvaloniaUI/Avalonia
PM> Install-Package Avalonia.Desktop

构建与发布项目

# 查看在线.NET Core项目依赖包
PS> dotnet nuget locals all --list
  # 复制 http-cache: C:\Users\Administrator\AppData\Local\NuGet\v3-cache
  # 复制 global-packages: C:\Users\Administrator\.nuget\packages\
# 离线还原.NET Core项目依赖包
PS> dotnet restore --source C:\Users\Administrator\.nuget\packages\ # 离线还原NuGet依赖包
PS> dotnet run --no-restore             # 运行项目(不还原NuGet依赖包)
PS> dotnet build --no-restore           # 生成项目(不还原NuGet依赖包)
PS> dotnet build ./*.csproj -c Release  # 生成项目(要还原NuGet依赖包) 接下来,发布项目。
PS> dotnet publish -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true -f net5.0 -r linux-x64 -o "./bin/Release/net5.0/publish/linux-x64"
PS> dotnet publish -c Release /p:PublishSingleFile=false /p:PublishTrimmed=false -f net5.0 -r win-x64 -o "./bin/Release/net5.0/publish/win-x64"
PS> dotnet publish ./*.csproj -c Release -r win-x64 -o "./bin/Release/net5.0/publish/win-x64"
# 安装
docker run --name nuget-server -itd -p 8880:80 --restart=always --env-file baget.env -v "$(pwd)/baget-data:/var/baget" loicsharma/baget:latest
# 配置 baget.env # ApiKey=
# 打包
dotnet pack
# 发布
dotnet nuget push -s http://nuget.xxx.com/v3/index.json -k {ApiKey} {PackageId}.{Version}.nupkg

开源框架及应用

# 使用 gRPC [ dotnet --version >= v3.0 ] 生命周期>
  # Client(发送请求)-> Client stub(压缩/解压)-> Client RPC Transfer(发送/接收)
  # -> Server RPC Transfer(接收/发送)-> Server stub(解压/压缩)-> Server(处理/响应)
> dotnet tool install -g dotnet-grpc # 安装 dotnet gRPC CLI工具(最新版)
> dotnet new grpc -n gRPC.Services # 新建Server工程< *.proto文件<: option csharp_namespace="gRPC.Services"
> dotnet-grpc add-file ../gRPC.Protos/*.proto -s Serve # 引入生成的protobuf文件到工程中\Serve\生成C#代码
  # 新建服务类 > 实现gRPC接口(继承) > 配置grpc服务类: endpoints.MapGrpcService<SmsService>();
> dotnet add package Google.Protobuf # 新建Client工程依赖
> dotnet-grpc add-file ../gRPC.Protos/*.proto -s Client # 引入生成的protobuf文件到工程中\Client\生成C#代码
# 使用 MsgPack [ dotnet --version >= v2.1 ] 项目中安装>
> Install-Package MessagePack
> Install-Package MessagePackAnalyzer
> Install-Package MessagePack.ImmutableCollection
> Install-Package MessagePack.ReactiveProperty
> Install-Package MessagePack.UnityShims
> Install-Package MessagePack.AspNetCoreMvcFormatter


学无先后达者为师!技术改变生活!.Net群1600800,嵌入式物联网群1600838

旨在提升小型团队的开发输出能力,由常用公共操作类(工具类)、分层架构基类、Ui组件,第三方组件封装,第三方业务接口封装,
 配套代码生成模板,权限等组成。

ASP.NET Core与Angular开发 - 网易云课堂

一个快速响应,移动优先的符合现代UI设计和SOLID架构的强力开发框架;包含登录,身份验证,用户/角色/权限管理,本地化,
 设置系统,审计日志记录,多租户,UI组件,异常处理系统等功能。

  • 类型反射
// 反射泛型方法,批量处理 Providers 继承于 AuthorizationProvider
foreach (var t in GetType().GetAssembly().GetTypes().Where(t => t.IsPublic && t.IsClass 
    && t.IsSubclassOf(typeof(Abp.Authorization.AuthorizationProvider))))
    Configuration.Authorization.Providers.GetType().GetMethods().FirstOrDefault(i => i.Name == "Add")
    ?.MakeGenericMethod(t).Invoke(Configuration.Authorization.Providers, new object[] { });
  • 同步Synchronous、异步Asynchronous
    • 同步:发送方发送请求,然后等待立即答复;可能通过异步I/O发生,但逻辑线程被保留;请求和应答之间的关联通常是隐式的,按请求的顺序执行;错误通常流回同一路径。
    • 异步:发送消息和进行其它事情;回复可能会在另一条路径上返回;消息可以由中介存储;可以多次尝试传递消息。
  • 通信方法REST < RPC < Message Event Hub dotnet presentations conf, Easy.MessageHub
  • 消息事件总线Message Event Hub
    • 后台任务/长时间任务Long-Running Work(one producer, one consumer)
    • 负载平衡/自动缩放生产Load Leveling(multiple producers, one consumer)
    • 负载均衡/自动缩放消费Load Balancing and Auto Scaling(multiple producers, multiple consumers)
    • 发布订阅Publish-Subscribe(one producer, multiple consumers)
    • 发布分流Partitioning(one producer, multiple consumers)
    • 多路复用/排它性消费Multiplexing with Exclusive Consumers(multiple producers, multiple consumers)
    • 状态处理Stateful Processing
    • 稀疏连通性Sparse Connectivity

About

ASP.NET Core 是一个跨平台的高性能开源框架,用于生成基于云且连接 Internet 的新式应用程序。 可用于建立Web应用、 IoT物联网、移动后端等。

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published