Giter Site home page Giter Site logo

dcdachui / soa Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jevonsflash/soa

0.0 0.0 0.0 3.19 MB

一个轻量级的微服务库,基于.Net 6 + Abp框架 可快速地将现有项目改造成为面向服务体系结构,实现模块间松耦合。

Home Page: https://blog.csdn.net/jevonsflash

C# 98.98% TSQL 1.02%

soa's Introduction

Soa

介绍

一个轻量级的微服务库,基于.Net 6 + Abp框架 可快速地将现有项目改造成为面向服务体系结构,实现模块间松耦合。

感谢

RabbitTeam 的项目 RabbitCloud

grissomlau 的项目 jimu

部分模块以及算法代码参考自以上项目

特点:

  • 支持DotNetty和Http两种模式的RPC
  • 支持自动路由发现注册与微服务健康监测
  • 支持模块以及模块的依赖关系
  • 支持简单对象(POCO)作为参数或返回类型
  • 支持登录与鉴权
  • 支持多语言/本地化

内容:

  • 基于Roslyn的动态客户代理类(Proxy模块)
  • POCO对象传输编解码(TypeConverter模块)
  • 基于DotNetty或者HTTP的RPC(Transport模块)
  • 路由服务发现(ServiceDiscovery模块)
  • 健康监测(HealthCheck模块)
  • 基于swagger的Api文档生成
  • 基于Attribute注解的路由配置
  • 基于Json配置文件的系统配置(Abp实现)
  • 基于Hangfire的计划任务
  • 基于Castle Windsor的Ioc(Abp实现)
  • 基于Log4Net的日志(Abp实现)
  • 基于AbpZero的用户系统
  • 基于EF,并实现模型的Repository仓储模式(Abp实现)

更新内容:

Date Version Content
V0.9.0 2022-5-17 初始版本
V0.9.1 2022-6-7 Sample添加对Docker的支持

快速开始

接下来简单介绍利用Soa库改造一个基于Asp Boilerplate项目的过程,完整示例请参考 Sample

网关(客户端) GatewaySample

  • 添加对Soa库的引用
  • 添加对Soa.Client库的引用

Startup.cs 文件

  1. 删除AddAbp
// services.AddAbp();
  1. 添加AddSoaClient
services.AddSoaClient<GatewaySampleWebHostModule>(new SoaClientOptions()
{
    IsDevelopment = _hostingEnvironment.IsDevelopment(),
    LoggerProvider = _appConfiguration["App:UseLogger"].ToUpper(),
    PlugInsPath = Path.Combine(_hostingEnvironment.WebRootPath, "PlugIns")
},true);
  1. 删除UseAbp
//app.UseAbp();
  1. 添加UseSoaClient
app.UseSoaClient(options => { options.UseAbpRequestLocalization = false; }); // Initializes Soa framework.

GatewaySampleWebHostModule.cs 文件

  1. 添加SoaClientModule模块依赖
[DependsOn(typeof(SoaClientModule))]
public class GatewaySampleWebHostModule: AbpModule
{
    //Your code
}
  • 配置 appsettings.json 文件
  • 配置 Hangfire

微服务抽象层 IService1

IService1Manager.cs 文件

  1. 构建接口IService1Manager并继承于ISoaService
  2. 添加Soa标签和Abp标签
[SoaAuthorize("permission_name")]     //Soa权限标签
[SoaServiceRoute("soa_api/service1")]           //Soa服务路由标签 
public interface IService1Manager : ISoaService
{
    //定义接口    
    [SoaService(CreatedBy = "linxiao", Comment = "bring a string to the world and say hello !")]
    [SoaAuthorize("permission_name")]    
    public string GetHelloWorld();

}
  • 将微服务抽象层引用添加至网关(客户端) GatewaySample

网关Ioc添加各微服务抽象层

var ass = Assembly.Load("Soa.Sample.IAuthorizedService");
IocManager.RegisterAssemblyByConvention(ass);

网关引入各微服务权限

 Configuration.Authorization.Providers.Add<AuthorizedServiceAuthorizationProvider>();

网关引入各微服务本地化资源

var loc = Configuration.Localization;
AuthorizedServiceLocalizationConfigurer.Configure(loc);

其他的Abp配置等等

微服务(服务端) Service1

  • 添加对微服务抽象层的引用

Program.cs 文件

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSoa<Service1HostModel>();
var webapp = builder.Build();
webapp.UseSoaServer();
webapp.Run();

Service1HostModel.cs 文件

  1. 添加SoaServerModule模块依赖
[DependsOn(typeof(SoaServerModule))]
public class Service1HostModel : AbpModule
{
    //Your code
}

Service1Manager.cs 文件

  1. 构建类Service1Manager
  2. 继承IService1Manager并实现其成员
public class Service1Manager : DomainService , IService1Manager
{
    //实现业务
    public string GetHelloWorld()
    {
        return "hello world !";
    }
}
  • 配置 appsettings.json 文件

关于appsettings.json的配置,请参考 配置说明

关于Hangfire的配置,请参考 定时任务

完整示例请参考 Sample

更多资讯请阅读系列博客

系列博客

  1. 使用Soa库+Abp搭建微服务项目框架(一):Abp与DDD相关知识回顾
  2. 使用Soa库+Abp搭建微服务项目框架(二):面向服务体系的介绍
  3. 使用Soa库+Abp搭建微服务项目框架(三):项目改造
  4. 使用Soa库+Abp搭建微服务项目框架(四):动态代理和RPC
  5. 使用Soa库+Abp搭建微服务项目框架(五):服务发现和健康监测

工具

Roslyn Syntax Tool

  • 此工具能将C#代码,转换成使用语法工厂构造器(SyntaxFactory)生成等效语法树代码

已知问题

作者信息

作者:林小

邮箱:[email protected]

License

The MIT License (MIT)

soa's People

Contributors

jevonsflash avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.