一個基於 .NET Core 2.0 開發的簡單易用的快速開發框架 - LinFx


LinFx

GitHub license

一個基於 .NET Core 2.0 開發的簡單易用的快速開發框架,遵循領域驅動設計(DDD)規范約束,提供實現事件驅動、事件回溯、響應式等特性的基礎設施。讓開發者享受到正真意義的面向對象設計模式來帶的美感。

LinFx.Extensions

Caching、DapperExtensions、Elasticsearch、EventBus、Metrics、Mongo、RabbitMQ

特性

  1. 領域驅動設計(DDD)
  2. 事件驅動架構 (EDA)
  3. 事件回溯 (ES)
  4. 最終一致性 (Eventually Consistent)
  5. 框架中每個組件都有基礎實現,最簡單時只需一個核心類庫就能跑起來
  6. 遵循端口與適配器模式,框架組件適配多種第三方組件實現,可從單體架構到面向服務架構按需擴展

設計規范

  1. 盡量使用.NET Standard和官方提供的類庫,第三方類庫設計成組件利用DI來按需組合。

安裝Nuget包

PM> Install-Package LinFx

開發環境

  1. Visual Studio 15.3+
  2. .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

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM