一个基于 .NET Core 2.0 开发的简单易用的快速开发框架 - LinFx
程序员文章站
2022-05-14 10:46:12
LinFx 一个基于 .NET Core 2.0 开发的简单易用的快速开发框架,遵循领域驱动设计(DDD)规范约束,提供实现事件驱动、事件回溯、响应式等特性的基础设施。让开发者享受到正真意义的面向对象设计模式来带的美感。 LinFx.Extensions Caching、DapperExtensio ......
linfx
一个基于 .net core 2.0 开发的简单易用的快速开发框架,遵循领域驱动设计(ddd)规范约束,提供实现事件驱动、事件回溯、响应式等特性的基础设施。让开发者享受到正真意义的面向对象设计模式来带的美感。
linfx.extensions
caching、dapperextensions、elasticsearch、eventbus、metrics、mongo、rabbitmq
特性
- 领域驱动设计(ddd)
- 事件驱动架构 (eda)
- 事件回溯 (es)
- 最终一致性 (eventually consistent)
- 框架中每个组件都有基础实现,最简单时只需一个核心类库就能跑起来
- 遵循端口与适配器模式,框架组件适配多种第三方组件实现,可从单体架构到面向服务架构按需扩展
设计规范
- 尽量使用.net standard和官方提供的类库,第三方类库设计成组件利用di来按需组合。
安装nuget包
pm> install-package linfx
开发环境
- visual studio 15.3+
- .net core sdk 2.2+
samples
public void configureservices(iservicecollection services) { services.addlinfx() .adddistributedrediscache(options => { options.configuration = configuration.getconnectionstring("reidsconnection"); }) .addmongodbcontext(options => { options.name = "default"; options.configuration = configuration.getconnectionstring("mongoconnection"); }) .addelasticsearch(options => { options.defaultindex = "default"; options.host = "http://10.0.1.112:9200"; }); }
eventbus
using linfx.extensions.eventbus.abstractions; using linfx.test.extensions.eventbus.events; using linfx.utils; using linfx.extensions.eventbus.rabbitmq; using microsoft.extensions.dependencyinjection; using system.threading.tasks; using xunit; using linfx.test.extensions.eventbus.eventhandling; using system.collections.generic; using system; namespace linfx.test.extensions.eventbus { public class eventbusrabbitmqtest { private readonly ieventbus _eventbus; public eventbusrabbitmqtest() { var services = new servicecollection(); services.addlinfx() .addeventbus(options => { options.durable = true; options.brokername = "tc_cloud_event_bus"; options.queuename = "tc_cloud_process_queue"; options.configureeventbus = (fx, builder) => builder.userabbitmq(fx, x => { x.host = "14.21.34.85"; x.username = "admin"; x.password = "admin.123456"; }); }); //services services.addtransient<orderstatuschangedtoawaitingvalidationintegrationeventhandler>(); //services.addtransient<orderstatuschangedtopaidintegrationeventhandler>(); var applicationservices = services.buildserviceprovider(); //configureeventbus _eventbus = applicationservices.getrequiredservice<ieventbus>(); _eventbus.subscribe<orderstatuschangedtoawaitingvalidationintegrationevent, orderstatuschangedtoawaitingvalidationintegrationeventhandler>(); //eventbus.subscribe<orderstatuschangedtopaidintegrationevent, orderstatuschangedtopaidintegrationeventhandler>(); } [fact] public async task should_call_handler_on_event_with_correct_sourceasync() { var orderid = guid.newguid().gethashcode() & ushort.maxvalue; var evt = new orderstatuschangedtoawaitingvalidationintegrationevent(orderid, new list<orderstockitem> { }); await _eventbus.publishasync(evt); //for (int i = 0; i < 2; i++) //{ // await _eventbus.publishasync(new clientcreateintergrationevent // { // clientid = idutils.createnewid().tostring(), // clientsecrets = new[] { "191d437f0cc3463b85669f2b570cdc21" }, // allowedgranttypes = new[] { "client_credentials" }, // allowedscopes = new[] { "api3.device" } // }); //} } } }
github
上一篇: ASP.NET Core使用EF Core操作MySql数据库
下一篇: 2020年是这样滴