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
https://github.com/linfx/LinFx