billyang / Surgingdemo
Licence: mit
surging 使用入门示例。完成一个基本业务的增删改查示例,并运用Surging强大的分布式缓存功能
Stars: ✭ 165
Projects that are alternatives of or similar to Surgingdemo
silky
The Silky framework is designed to help developers quickly build a microservice development framework through simple code and configuration under the .net platform.
Stars: ✭ 146 (-11.52%)
Mutual labels: dotnetcore, rpc
Identity.dapper
Identity package that uses Dapper instead EntityFramework for use with .NET Core
Stars: ✭ 234 (+41.82%)
Mutual labels: dapper, dotnetcore
Signalw
Even simpler and faster real-time web for ASP.NET Core.
Stars: ✭ 125 (-24.24%)
Mutual labels: rpc, dotnetcore
Gb28181.solution
Linux/Win/Docker/kubernetes/Chart/Kustomize/GB28181/SIP/RTP/SDP/WebRTC/作为上下级域/平台级联互联
Stars: ✭ 323 (+95.76%)
Mutual labels: rpc, dotnetcore
Aspnetcore Practice
ASP.NET Core 專案練習集合,ASP.NET Core Practice Projects
Stars: ✭ 80 (-51.52%)
Mutual labels: dapper, dotnetcore
Vue.netcore
.NetCore+Vue2/Vue3+Element plus,前后端分离,不一样的快速开发框架;提供Vue2、Vue3版本,。http://www.volcore.xyz/
Stars: ✭ 2,338 (+1316.97%)
Mutual labels: dapper, dotnetcore
Ginrpc
gin auto binding,grpc, and annotated route,gin 注解路由, grpc,自动参数绑定工具
Stars: ✭ 157 (-4.85%)
Mutual labels: rpc
Active Directory B2c Dotnetcore Webapp
An ASP.NET Core web application that can sign in a user using Azure AD B2C, get an access token using MSAL.NET and call an API.
Stars: ✭ 160 (-3.03%)
Mutual labels: dotnetcore
Nbcz admin
asp.net MVC5 + Dapper + layUI/easyUI 通用权限管理系统、后台框架、信息管理系统基础框架
Stars: ✭ 163 (-1.21%)
Mutual labels: dapper
Serverless Next.js
⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
Stars: ✭ 2,977 (+1704.24%)
Mutual labels: api-gateway
Tree Gateway
This is a full featured and free API Gateway
Stars: ✭ 160 (-3.03%)
Mutual labels: api-gateway
Tensorflow.net
.NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#.
Stars: ✭ 2,188 (+1226.06%)
Mutual labels: dotnetcore
Appmetrics
App Metrics is an open-source and cross-platform .NET library used to record and report metrics within an application.
Stars: ✭ 1,986 (+1103.64%)
Mutual labels: dotnetcore
Mmalsharp
C# wrapper to Broadcom's MMAL with an API to the Raspberry Pi camera.
Stars: ✭ 152 (-7.88%)
Mutual labels: dotnetcore
Dop
JavaScript implementation for Distributed Object Protocol
Stars: ✭ 163 (-1.21%)
Mutual labels: rpc
SurgingDemo
base surging
前言:
Surging 分布式微服务框架适合做什么
- 企业级互联网架构平台;
- 传统大型项目,伸缩性很强的项目,可应对突发的流量暴增(比如双十一订单暴增);
- 移动互联网项目,比如为了因对突发的因营销等带来的流量暴增,评论暴增等等情况;
欢迎补充...
本示例项目是基于 Surging https://github.com/dotnetcore/surging
旨在描述如何在 surging 的基础上运行dapper完成一个增删改的例子
1.在sqlserver中建立Test 数据库
运行下面脚本,生成user表
2.运行Surging Demo
clone代码 git clone https://github.com/billyang/SurgingDemo.git
nuget
引用,直接从 surging 项目引用,没有拷贝一份放在自己的解决方案,
因为本示例项目没有从假设目录结构如下:
D:\git\surging
D:\git\SurgingDemo
Surging
和SurgingDemo
在同一个目录
最终保持这样做的好处:
- 是和 surging 保持最新代码
- 是方便学习surging和调试,毕竟你想使用surging、理解surging才是踏出第一步
Surging.ApiGateway 提供了服务管理以及网关统一访问入口。 目前开发还不完善,如果现在要用于正式开发建议自己要部分重写 ApiGateway,加入权限验证。相信等到1.0版本作者也会把数据监控、流量控制、数据安全、分流控制、身份认证等管理功能加入,当然这些功能并不会影响正常使用。
本示例服务注册中心使用 consul,因为调试简单,只需 consul agent -dev 即可开启consul
假设你已经把SurgingDemo已运行起来了,即可对根据Dapper对User进行增删改查
介绍一下本示例各项目的职责
Bill.Demo.Core 用户定义数据模型
Bill.Demo.DapperCore (Dapper仓储,其中仓储需继承 UserRepository: Surging.Core.CPlatform.Ioc.BaseRepository)
public class UserRepository: BaseRepository, IBaseRepository<User>
{
/// <summary>
/// 创建一个用户
/// </summary>
/// <param name="entity">用户</param>
/// <param name="connectionString">链接字符串</param>
/// <returns></returns>
public Task<Boolean> CreateEntity(User entity, String connectionString = null)
{
using (IDbConnection conn = DataBaseConfig.GetSqlConnection(connectionString))
{
string insertSql = @"INSERT INTO dbo.auth_User
( TenantId ,
Name ,
Password ,
SecurityStamp ,
FullName ,
Surname ,
PhoneNumber ,
IsPhoneNumberConfirmed ,
EmailAddress ,
IsEmailConfirmed ,
EmailConfirmationCode ,
IsActive ,
PasswordResetCode ,
LastLoginTime ,
IsLockoutEnabled ,
AccessFailedCount ,
LockoutEndDateUtc
)
VALUES ( @tenantid ,
@name ,
@password ,
@securitystamp ,
@fullname ,
@surname ,
@phonenumber ,
@isphonenumberconfirmed ,
@emailaddress ,
@isemailconfirmed ,
@emailconfirmationcode ,
@isactive ,
@passwordresetcode ,
@lastlogintime ,
@islockoutenabled ,
@accessfailedcount ,
@lockoutenddateutc
);";
return Task.FromResult<Boolean>(conn.Execute(insertSql, entity) > 0);
}
}
}
Bill.Demo.IModuleServices (和Surging项目一样,定义模块服务接口以及领域模型)
Task<UserDto> GetUserById(Int64 id);
Task<Boolean> UpdateUser(UserDto user);
Task<Boolean> DeleteUser(Int64 userId);
Bill.Demo.ModuleServices (和Surging项目一样,实现模块服务)
如:
public async Task<UserDto> GetUserById(Int64 id)
{
var user = await _repository.GetEntityById(id);
return new UserDto()
{
Id = user.Id,
EmailAddress = user.EmailAddress,
Name = user.Name,
PhoneNumber = user.PhoneNumber,
Surname = user.Surname,
TenantId = user.TenantId,
FullName = user.FullName,
};
}
public async Task<Boolean> UpdateUser(UserDto user)
{
var entity = await _repository.GetEntityById(user.Id);
entity.Name = user.Name;
entity.Password = user.Password;
entity.FullName = user.FullName;
entity.Surname = user.Surname;
entity.EmailAddress = user.EmailAddress;
entity.PhoneNumber = user.PhoneNumber;
return await _repository.Update(entity);
}
public async Task<Boolean> DeleteUser(Int64 userId)
{
return await _repository.Delete(userId);
}
Bill.Demo.Services.Server 服务
Bill.Demo.Web 客户端
public async Task<IActionResult> Delete(Int64 id)
{
var service = ServiceLocator.GetService<IServiceProxyFactory>();
var userProxy = service.CreateProxy<IUserService>("User");
await userProxy.DeleteUser(id);
return RedirectToAction("User");
}
public async Task<JsonResult> GetUser(Int64 id)
{
var service = ServiceLocator.GetService<IServiceProxyFactory>();
var userProxy = service.CreateProxy<IUserService>("User");
var output= await userProxy.GetUserById(id);
return new JsonResult(output);
}
public async Task<JsonResult> Update(UserDto dto)
{
var service = ServiceLocator.GetService<IServiceProxyFactory>();
var userProxy = service.CreateProxy<IUserService>("User");
var output = await userProxy.UpdateUser(dto);
return new JsonResult(output);
}
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].