From a304e908aa6f826a54345921b2f5145552c04ff0 Mon Sep 17 00:00:00 2001 From: Dai Mr <1822802785@qq.com> Date: Wed, 13 Nov 2024 00:30:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ServiceCollectionExtensions.cs | 8 +- .../JiSheCollectBusApplicationModule.cs | 36 +++- JiShe.CollectBus.Application/Jobs/TestJob.cs | 3 +- .../Attributes/DependsOnAttribute.cs | 24 --- .../Extensions/CollectionExtensions.cs | 9 - .../DependencyInjectionExtensions.cs | 184 +++++++++--------- .../DependencyInjections/IScopedDependency.cs | 12 +- .../ISingletonDependency.cs | 12 +- .../ITransientDependency.cs | 12 +- .../Extensions/ObjectExtensions.cs | 1 + .../Extensions/StringExtensions.cs | 10 +- .../Interfaces/IJiSheModule.cs | 16 -- .../JiShe.CollectBus.Common.csproj | 6 + .../Models/CommandReuslt.cs | 5 +- .../Models/ReqParameter.cs | 5 +- .../Models/ServiceContext.cs | 29 --- JiShe.CollectBus.Common/RequiredAttribute.cs | 17 -- .../DependencyInjectionExtensions.cs | 170 ++++++++-------- .../ServiceCollectionExtensions.cs | 68 ++++--- .../JiShe.CollectBus.Console.csproj | 10 +- JiShe.CollectBus.Console/Program.cs | 16 +- .../JiSheCollectBusCoreModule.cs | 50 +++++ .../Plugins/TcpServicePlugin.cs | 4 +- ...iSheCollectBusEntityFrameworkCoreModule.cs | 11 ++ .../JiShe.CollectBus.Host.csproj | 53 ++--- JiShe.CollectBus.Host/Startup.cs | 6 +- JiShe.CollectBus.Host/appsettings.json | 3 +- .../JiSheCollectBusMongoDBModule.cs | 9 +- .../MongoBaseRepository.cs | 3 +- JiShe.CollectBus.MongoDB/MongoContext.cs | 6 - JiShe.CollectBus.MongoDB/UnitOfWork.cs | 3 +- .../JiSheCollectBusTestProtocolModule.cs | 20 ++ .../TestProtocolPlugin.cs | 15 +- .../JiSheCollectBusProtocolModule.cs | 21 ++ .../StandardProtocolPlugin.cs | 4 +- .../JiSheCollectBusRabbitMqModule.cs | 21 +- JiShe.CollectBus.RabbitMQ/Senders/NSender.cs | 2 +- 37 files changed, 466 insertions(+), 418 deletions(-) delete mode 100644 JiShe.CollectBus.Common/Attributes/DependsOnAttribute.cs delete mode 100644 JiShe.CollectBus.Common/Interfaces/IJiSheModule.cs delete mode 100644 JiShe.CollectBus.Common/Models/ServiceContext.cs delete mode 100644 JiShe.CollectBus.Common/RequiredAttribute.cs create mode 100644 JiShe.CollectBus.Core/JiSheCollectBusCoreModule.cs create mode 100644 JiShe.CollectBus.EntityFrameworkCore/JiSheCollectBusEntityFrameworkCoreModule.cs create mode 100644 JiShe.CollectBus.Protocol.Test/JiSheCollectBusTestProtocolModule.cs create mode 100644 JiShe.CollectBus.Protocol/JiSheCollectBusProtocolModule.cs diff --git a/JiShe.CollectBus.Application/Extensions/ServiceCollections/ServiceCollectionExtensions.cs b/JiShe.CollectBus.Application/Extensions/ServiceCollections/ServiceCollectionExtensions.cs index db6fa96..caae72a 100644 --- a/JiShe.CollectBus.Application/Extensions/ServiceCollections/ServiceCollectionExtensions.cs +++ b/JiShe.CollectBus.Application/Extensions/ServiceCollections/ServiceCollectionExtensions.cs @@ -13,6 +13,7 @@ namespace Microsoft.Extensions.DependencyInjection /// public static IServiceCollection AddJobs(this IServiceCollection services, IConfiguration configuration) { + var interfaceType = typeof(IBaseJob); var assembly = Assembly.GetExecutingAssembly(); @@ -21,7 +22,12 @@ namespace Microsoft.Extensions.DependencyInjection { if (type.IsClass && type.GetInterfaces().Contains(interfaceType)) { - RecurringJob.AddOrUpdate(type.Name, ()=>((type as IBaseJob)!).Execute(), Cron.Minutely, TimeZoneInfo.Utc); + var instance = services.GetServiceProviderOrNull().GetService(type); + + //var instance = services.GetObject(); + + //var instance = Activator.CreateInstance(type); + RecurringJob.AddOrUpdate(type.Name, () => type.GetMethod("Execute").Invoke(instance,null), Cron.Minutely); } } return services; diff --git a/JiShe.CollectBus.Application/JiSheCollectBusApplicationModule.cs b/JiShe.CollectBus.Application/JiSheCollectBusApplicationModule.cs index d482caa..9435dca 100644 --- a/JiShe.CollectBus.Application/JiSheCollectBusApplicationModule.cs +++ b/JiShe.CollectBus.Application/JiSheCollectBusApplicationModule.cs @@ -1,15 +1,39 @@ -using JiShe.CollectBus.Common.Interfaces; -using JiShe.CollectBus.Common.Models; +using System.Reflection; +using Hangfire; +using JiShe.CollectBus.Common.Jobs; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.Modularity; namespace JiShe.CollectBus.Application { - public class JiSheCollectBusApplicationModule: IJiSheModule + public class JiSheCollectBusApplicationModule: AbpModule { - public void ConfigureServices(ServiceContext context) + public override void ConfigureServices(ServiceConfigurationContext context) { - var configuration = context.Configuration; - context.Services.AddJobs(configuration); + //var configuration = context.Services.GetConfiguration(); + //context.Services.AddJobs(configuration); + } + + public override void OnPostApplicationInitialization(ApplicationInitializationContext context) + { + + var interfaceType = typeof(IBaseJob); + var assembly = Assembly.GetExecutingAssembly(); + + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterfaces().Contains(interfaceType)) + { + var instance = context.ServiceProvider.GetService(type); + + //var instance = services.GetObject(); + + //var instance = Activator.CreateInstance(type); + RecurringJob.AddOrUpdate(type.Name, () => type.GetMethod("Execute").Invoke(instance, null), Cron.Minutely); + } + } } } } diff --git a/JiShe.CollectBus.Application/Jobs/TestJob.cs b/JiShe.CollectBus.Application/Jobs/TestJob.cs index a923ade..bd98b37 100644 --- a/JiShe.CollectBus.Application/Jobs/TestJob.cs +++ b/JiShe.CollectBus.Application/Jobs/TestJob.cs @@ -6,10 +6,11 @@ using System.Threading.Tasks; using JiShe.CollectBus.Common.Jobs; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Volo.Abp.DependencyInjection; namespace JiShe.CollectBus.Application.Jobs { - public class TestJob : IBaseJob + public class TestJob : IBaseJob,ISingletonDependency { private readonly ILogger _logger; private readonly IConfiguration _configuration; diff --git a/JiShe.CollectBus.Common/Attributes/DependsOnAttribute.cs b/JiShe.CollectBus.Common/Attributes/DependsOnAttribute.cs deleted file mode 100644 index db05c99..0000000 --- a/JiShe.CollectBus.Common/Attributes/DependsOnAttribute.cs +++ /dev/null @@ -1,24 +0,0 @@ -using JiShe.CollectBus.Common.Interfaces; - -namespace JiShe.CollectBus.Common.Attributes -{ - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] - public class DependsOnAttribute : Attribute - { - // 依赖的模块 - public Type ModuleType { get; private init; } - public DependsOnAttribute(Type type) - { - ModuleType = type; - } - } - - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] - public sealed class DependsOnAttribute : DependsOnAttribute - where TModule : IJiSheModule - { - public DependsOnAttribute() : base(typeof(TModule)) - { - } - } -} diff --git a/JiShe.CollectBus.Common/Extensions/CollectionExtensions.cs b/JiShe.CollectBus.Common/Extensions/CollectionExtensions.cs index 6d493a4..fd9d246 100644 --- a/JiShe.CollectBus.Common/Extensions/CollectionExtensions.cs +++ b/JiShe.CollectBus.Common/Extensions/CollectionExtensions.cs @@ -11,15 +11,6 @@ namespace JiShe.CollectBus.Common.Extensions /// public static class CollectionExtensions { - /// - /// Checks whatever given collection object is null or has no item. - /// - [Description("ļ϶ǷΪnullûĿ")] - public static bool IsNullOrEmpty([CanBeNull] this ICollection source) - { - return source == null || source.Count <= 0; - } - /// /// Adds an item to the collection if it's not already in the collection. /// diff --git a/JiShe.CollectBus.Common/Extensions/DependencyInjections/DependencyInjectionExtensions.cs b/JiShe.CollectBus.Common/Extensions/DependencyInjections/DependencyInjectionExtensions.cs index becb781..c8197ea 100644 --- a/JiShe.CollectBus.Common/Extensions/DependencyInjections/DependencyInjectionExtensions.cs +++ b/JiShe.CollectBus.Common/Extensions/DependencyInjections/DependencyInjectionExtensions.cs @@ -1,104 +1,104 @@ -using JiShe.CollectBus.Common.Extensions.DependencyInjections; -using System.Reflection; -using JiShe.CollectBus.Common.Interfaces; -using Microsoft.Extensions.Hosting; -using System; -using Microsoft.Extensions.Configuration; -using Serilog; +//using JiShe.CollectBus.Common.Extensions.DependencyInjections; +//using System.Reflection; +//using JiShe.CollectBus.Common.Abstractions; +//using Microsoft.Extensions.Hosting; +//using System; +//using Microsoft.Extensions.Configuration; +//using Serilog; -// ReSharper disable once CheckNamespace -namespace Microsoft.Extensions.DependencyInjection -{ - public static class DependencyInjectionExtensions - { - public static IServiceCollection ModuleRegister(this IServiceCollection services, IConfiguration configuration) - { - var assemblies = GetBinAssemblies(); +//// ReSharper disable once CheckNamespace +//namespace Microsoft.Extensions.DependencyInjection +//{ +// public static class DependencyInjectionExtensions +// { +// public static IServiceCollection ModuleRegister(this IServiceCollection services, IConfiguration configuration) +// { +// var assemblies = GetBinAssemblies(); - foreach (var assembly in assemblies) - { - var allTypes = assembly.GetTypes(); - foreach (var type in allTypes) - { - if (typeof(IJiSheModule).IsAssignableFrom(type) && type is { IsClass: true, IsAbstract: false }) - { - Log.Logger.Information($"正在加载模块{type.Name}..."); - var instance = Activator.CreateInstance(type); - _ = (type.GetMethod("ConfigureServices")?.Invoke(instance, [services, configuration])); - } - } - } +// foreach (var assembly in assemblies) +// { +// var allTypes = assembly.GetTypes(); +// foreach (var type in allTypes) +// { +// if (typeof(IJiSheModule).IsAssignableFrom(type) && type is { IsClass: true, IsAbstract: false }) +// { +// Log.Logger.Information($"正在加载模块{type.Name}..."); +// var instance = Activator.CreateInstance(type); +// _ = (type.GetMethod("ConfigureServices")?.Invoke(instance, [services, configuration])); +// } +// } +// } - return services; - } +// return services; +// } - public static IServiceCollection ServiceRegister(this IServiceCollection services) - { - var assemblies = GetBinAssemblies(); +// public static IServiceCollection ServiceRegister(this IServiceCollection services) +// { +// var assemblies = GetBinAssemblies(); - foreach (var assembly in assemblies) - { - var allTypes = assembly.GetTypes(); - foreach (var type in allTypes) - { - if (type is not { IsClass: true, IsAbstract: false }) continue; - if (typeof(ISingletonDependency).IsAssignableFrom(type)) - { - var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ISingletonDependency") && !p.FullName.Contains("IDisposable")); - foreach (var interfaceType in interfaceTypes) - { - Log.Logger.Information($"正在IOC注入ISingletonDependency {type.Name}..."); - services.AddSingleton(interfaceType, type); - } - } +// foreach (var assembly in assemblies) +// { +// var allTypes = assembly.GetTypes(); +// foreach (var type in allTypes) +// { +// if (type is not { IsClass: true, IsAbstract: false }) continue; +// if (typeof(ISingletonDependency).IsAssignableFrom(type)) +// { +// var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ISingletonDependency") && !p.FullName.Contains("IDisposable")); +// foreach (var interfaceType in interfaceTypes) +// { +// Log.Logger.Information($"正在IOC注入ISingletonDependency {type.Name}..."); +// services.AddSingleton(interfaceType, type); +// } +// } - if (typeof(ITransientDependency).IsAssignableFrom(type)) - { - var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ITransientDependency") && !p.FullName.Contains("IDisposable")); - foreach (var interfaceType in interfaceTypes) - { - Log.Logger.Information($"正在IOC注入ITransientDependency {type.Name}..."); - services.AddTransient(interfaceType, type); - } - } +// if (typeof(ITransientDependency).IsAssignableFrom(type)) +// { +// var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ITransientDependency") && !p.FullName.Contains("IDisposable")); +// foreach (var interfaceType in interfaceTypes) +// { +// Log.Logger.Information($"正在IOC注入ITransientDependency {type.Name}..."); +// services.AddTransient(interfaceType, type); +// } +// } - if (typeof(IScopedDependency).IsAssignableFrom(type)) - { - var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("IScopedDependency") && !p.FullName.Contains("IDisposable")); - foreach (var interfaceType in interfaceTypes) - { - Log.Logger.Information($"正在IOC注入IScopedDependency {type.Name}..."); - services.AddScoped(interfaceType, type); - } - } - } - } +// if (typeof(IScopedDependency).IsAssignableFrom(type)) +// { +// var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("IScopedDependency") && !p.FullName.Contains("IDisposable")); +// foreach (var interfaceType in interfaceTypes) +// { +// Log.Logger.Information($"正在IOC注入IScopedDependency {type.Name}..."); +// services.AddScoped(interfaceType, type); +// } +// } +// } +// } - return services; - } +// return services; +// } - private static IEnumerable GetBinAssemblies() - { - var directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); - if (!directory.Exists) return []; +// private static IEnumerable GetBinAssemblies() +// { +// var directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); +// if (!directory.Exists) return []; - var files = directory.GetFiles("JiShe.CollectBus.*.dll"); +// var files = directory.GetFiles("JiShe.CollectBus.*.dll"); - var assemblies = new List(); - foreach (var file in files) - { - try - { - var assembly = Assembly.LoadFrom(file.FullName); - assemblies.Add(assembly); - } - catch (Exception ex) - { - Console.WriteLine($"Error loading assembly from {file.FullName}: {ex.Message}"); - } - } +// var assemblies = new List(); +// foreach (var file in files) +// { +// try +// { +// var assembly = Assembly.LoadFrom(file.FullName); +// assemblies.Add(assembly); +// } +// catch (Exception ex) +// { +// Console.WriteLine($"Error loading assembly from {file.FullName}: {ex.Message}"); +// } +// } - return assemblies; - } - } -} +// return assemblies; +// } +// } +//} diff --git a/JiShe.CollectBus.Common/Extensions/DependencyInjections/IScopedDependency.cs b/JiShe.CollectBus.Common/Extensions/DependencyInjections/IScopedDependency.cs index 2b4fe1c..349cbf8 100644 --- a/JiShe.CollectBus.Common/Extensions/DependencyInjections/IScopedDependency.cs +++ b/JiShe.CollectBus.Common/Extensions/DependencyInjections/IScopedDependency.cs @@ -1,6 +1,6 @@ -namespace JiShe.CollectBus.Common.Extensions.DependencyInjections -{ - public interface IScopedDependency - { - } -} +//namespace JiShe.CollectBus.Common.Extensions.DependencyInjections +//{ +// public interface IScopedDependency +// { +// } +//} diff --git a/JiShe.CollectBus.Common/Extensions/DependencyInjections/ISingletonDependency.cs b/JiShe.CollectBus.Common/Extensions/DependencyInjections/ISingletonDependency.cs index c3f89fa..83bbdb8 100644 --- a/JiShe.CollectBus.Common/Extensions/DependencyInjections/ISingletonDependency.cs +++ b/JiShe.CollectBus.Common/Extensions/DependencyInjections/ISingletonDependency.cs @@ -1,6 +1,6 @@ -namespace JiShe.CollectBus.Common.Extensions.DependencyInjections -{ - public interface ISingletonDependency - { - } -} +//namespace JiShe.CollectBus.Common.Extensions.DependencyInjections +//{ +// public interface ISingletonDependency +// { +// } +//} diff --git a/JiShe.CollectBus.Common/Extensions/DependencyInjections/ITransientDependency.cs b/JiShe.CollectBus.Common/Extensions/DependencyInjections/ITransientDependency.cs index 4c2092c..ea2d48d 100644 --- a/JiShe.CollectBus.Common/Extensions/DependencyInjections/ITransientDependency.cs +++ b/JiShe.CollectBus.Common/Extensions/DependencyInjections/ITransientDependency.cs @@ -1,6 +1,6 @@ -namespace JiShe.CollectBus.Common.Extensions.DependencyInjections -{ - public interface ITransientDependency - { - } -} +//namespace JiShe.CollectBus.Common.Extensions.DependencyInjections +//{ +// public interface ITransientDependency +// { +// } +//} diff --git a/JiShe.CollectBus.Common/Extensions/ObjectExtensions.cs b/JiShe.CollectBus.Common/Extensions/ObjectExtensions.cs index 0d4b260..b0cfe28 100644 --- a/JiShe.CollectBus.Common/Extensions/ObjectExtensions.cs +++ b/JiShe.CollectBus.Common/Extensions/ObjectExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Linq; using System.Reflection; diff --git a/JiShe.CollectBus.Common/Extensions/StringExtensions.cs b/JiShe.CollectBus.Common/Extensions/StringExtensions.cs index c41267c..0588093 100644 --- a/JiShe.CollectBus.Common/Extensions/StringExtensions.cs +++ b/JiShe.CollectBus.Common/Extensions/StringExtensions.cs @@ -16,15 +16,7 @@ namespace JiShe.CollectBus.Common.Extensions { public static class StringExtensions { - /// Determines whether [is null or white space]. - /// The string. - /// - /// true if [is null or white space] [the specified string]; otherwise, false. - [Description("检查是否为NULL或空格")] - public static bool IsNullOrWhiteSpace(this string str) - { - return string.IsNullOrWhiteSpace(str); - } + /// Determines whether [is null or empty]. /// The string. diff --git a/JiShe.CollectBus.Common/Interfaces/IJiSheModule.cs b/JiShe.CollectBus.Common/Interfaces/IJiSheModule.cs deleted file mode 100644 index 95ccad3..0000000 --- a/JiShe.CollectBus.Common/Interfaces/IJiSheModule.cs +++ /dev/null @@ -1,16 +0,0 @@ -using JiShe.CollectBus.Common.Models; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace JiShe.CollectBus.Common.Interfaces -{ - public interface IJiSheModule - { - /// - /// 模块中的依赖注入 - /// - /// 模块服务上下文 - void ConfigureServices(ServiceContext context); - } -} diff --git a/JiShe.CollectBus.Common/JiShe.CollectBus.Common.csproj b/JiShe.CollectBus.Common/JiShe.CollectBus.Common.csproj index e22466b..5722609 100644 --- a/JiShe.CollectBus.Common/JiShe.CollectBus.Common.csproj +++ b/JiShe.CollectBus.Common/JiShe.CollectBus.Common.csproj @@ -9,9 +9,15 @@ + + + + + + diff --git a/JiShe.CollectBus.Common/Models/CommandReuslt.cs b/JiShe.CollectBus.Common/Models/CommandReuslt.cs index 0d75c42..1a83b51 100644 --- a/JiShe.CollectBus.Common/Models/CommandReuslt.cs +++ b/JiShe.CollectBus.Common/Models/CommandReuslt.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using JiShe.CollectBus.Common.Enums; namespace JiShe.CollectBus.Common.Models @@ -16,14 +17,14 @@ namespace JiShe.CollectBus.Common.Models public int CmdLength { get; set; } - [Required(true)] + [Required] public string A { get; set; } public int MSA { get; set; } public AFN AFN { get; set; } - [Required(true)] + [Required] public Seq Seq { get; set; } public int Pn { get; set; } diff --git a/JiShe.CollectBus.Common/Models/ReqParameter.cs b/JiShe.CollectBus.Common/Models/ReqParameter.cs index dba22df..96e2542 100644 --- a/JiShe.CollectBus.Common/Models/ReqParameter.cs +++ b/JiShe.CollectBus.Common/Models/ReqParameter.cs @@ -1,4 +1,5 @@  +using System.ComponentModel.DataAnnotations; using JiShe.CollectBus.Common.Enums; namespace JiShe.CollectBus.Common.Models @@ -12,10 +13,10 @@ namespace JiShe.CollectBus.Common.Models public PRM PRM { get; set; } = PRM.启动站报文; - [Required(true)] + [Required] public string A { get; set; } - [Required(true)] + [Required] public Seq Seq { get; set; } public int MSA { get; set; } = 0; diff --git a/JiShe.CollectBus.Common/Models/ServiceContext.cs b/JiShe.CollectBus.Common/Models/ServiceContext.cs deleted file mode 100644 index 7258cfc..0000000 --- a/JiShe.CollectBus.Common/Models/ServiceContext.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace JiShe.CollectBus.Common.Models -{ - public class ServiceContext - { - internal ServiceContext(IServiceCollection serviceCollection, IConfiguration configuration) - { - Services = serviceCollection; - Configuration = configuration; - } - - /// - /// 依赖注入服务 - /// - public IServiceCollection Services { get; } - - /// - /// 配置 - /// - public IConfiguration Configuration { get; } - } -} diff --git a/JiShe.CollectBus.Common/RequiredAttribute.cs b/JiShe.CollectBus.Common/RequiredAttribute.cs deleted file mode 100644 index 3c1950a..0000000 --- a/JiShe.CollectBus.Common/RequiredAttribute.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace JiShe.CollectBus.Common -{ - public class RequiredAttribute:Attribute - { - public bool IsRequired { get; private set; } - - public RequiredAttribute(bool isRequired) - { - IsRequired = isRequired; - } - - } -} diff --git a/JiShe.CollectBus.Console/Extensions/DependencyInjections/DependencyInjectionExtensions.cs b/JiShe.CollectBus.Console/Extensions/DependencyInjections/DependencyInjectionExtensions.cs index ef6741f..e30f2a1 100644 --- a/JiShe.CollectBus.Console/Extensions/DependencyInjections/DependencyInjectionExtensions.cs +++ b/JiShe.CollectBus.Console/Extensions/DependencyInjections/DependencyInjectionExtensions.cs @@ -1,94 +1,92 @@ -using JiShe.CollectBus.Common.Extensions.DependencyInjections; -using JiShe.CollectBus.Protocol.Contracts.Attributes; -using System.Reflection; -using JiShe.CollectBus.Common.Interfaces; -using TouchSocket.Core; -using Microsoft.Extensions.Hosting; -using System; -using Serilog; +//using JiShe.CollectBus.Common.Extensions.DependencyInjections; +//using JiShe.CollectBus.Protocol.Contracts.Attributes; +//using System.Reflection; +//using TouchSocket.Core; +//using System; +//using Serilog; -// ReSharper disable once CheckNamespace -namespace Microsoft.Extensions.DependencyInjection -{ - public static class DependencyInjectionExtensions - { - public static void PluginServiceRegister(this IServiceCollection services, string pluginPath = "") - { - if (pluginPath.IsNullOrWhiteSpace()) - { - pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"); - } - var assemblies = GetAssembliesFromFolder(pluginPath); +//// ReSharper disable once CheckNamespace +//namespace Microsoft.Extensions.DependencyInjection +//{ +// public static class DependencyInjectionExtensions +// { +// public static void PluginServiceRegister(this IServiceCollection services, string pluginPath = "") +// { +// if (pluginPath.IsNullOrWhiteSpace()) +// { +// pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"); +// } +// var assemblies = GetAssembliesFromFolder(pluginPath); - foreach (var assembly in assemblies) - { - var allTypes = assembly.GetTypes(); - foreach (var type in allTypes) - { - if (typeof(ISingletonDependency).IsAssignableFrom(type) && type is { IsClass: true, IsAbstract: false }) - { - var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ISingletonDependency")); - foreach (var interfaceType in interfaceTypes) - { - var attr = type.GetCustomAttribute(); - if (attr == null) continue; - Log.Logger.Information($"正在加载插件{attr.Name}..."); - var serviceDescriptor = new ServiceDescriptor(interfaceType, attr.Name, type, ServiceLifetime.Singleton); - services.Add(serviceDescriptor); - } - } +// foreach (var assembly in assemblies) +// { +// var allTypes = assembly.GetTypes(); +// foreach (var type in allTypes) +// { +// if (typeof(ISingletonDependency).IsAssignableFrom(type) && type is { IsClass: true, IsAbstract: false }) +// { +// var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ISingletonDependency")); +// foreach (var interfaceType in interfaceTypes) +// { +// var attr = type.GetCustomAttribute(); +// if (attr == null) continue; +// Log.Logger.Information($"正在加载插件{attr.Name}..."); +// var serviceDescriptor = new ServiceDescriptor(interfaceType, attr.Name, type, ServiceLifetime.Singleton); +// services.Add(serviceDescriptor); +// } +// } - if (typeof(ITransientDependency).IsAssignableFrom(type) && type is { IsClass: true, IsAbstract: false }) - { - var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ITransientDependency")); - foreach (var interfaceType in interfaceTypes) - { - var attr = type.GetCustomAttribute(); - if (attr == null) continue; - Log.Logger.Information($"正在加载插件{attr.Name}..."); - var serviceDescriptor = new ServiceDescriptor(interfaceType, attr.Name, type, ServiceLifetime.Transient); - services.Add(serviceDescriptor); - } - } +// if (typeof(ITransientDependency).IsAssignableFrom(type) && type is { IsClass: true, IsAbstract: false }) +// { +// var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ITransientDependency")); +// foreach (var interfaceType in interfaceTypes) +// { +// var attr = type.GetCustomAttribute(); +// if (attr == null) continue; +// Log.Logger.Information($"正在加载插件{attr.Name}..."); +// var serviceDescriptor = new ServiceDescriptor(interfaceType, attr.Name, type, ServiceLifetime.Transient); +// services.Add(serviceDescriptor); +// } +// } - if (typeof(IScopedDependency).IsAssignableFrom(type) && type is { IsClass: true, IsAbstract: false }) - { - var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("IScopedDependency")); - foreach (var interfaceType in interfaceTypes) - { - var attr = type.GetCustomAttribute(); - if (attr == null) continue; - Log.Logger.Information($"正在加载插件{attr.Name}..."); - var serviceDescriptor = new ServiceDescriptor(interfaceType, attr.Name, type, ServiceLifetime.Scoped); - services.Add(serviceDescriptor); - } - } - } - } - } +// if (typeof(IScopedDependency).IsAssignableFrom(type) && type is { IsClass: true, IsAbstract: false }) +// { +// var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("IScopedDependency")); +// foreach (var interfaceType in interfaceTypes) +// { +// var attr = type.GetCustomAttribute(); +// if (attr == null) continue; +// Log.Logger.Information($"正在加载插件{attr.Name}..."); +// var serviceDescriptor = new ServiceDescriptor(interfaceType, attr.Name, type, ServiceLifetime.Scoped); +// services.Add(serviceDescriptor); +// } +// } +// } +// } +// } - private static IEnumerable GetAssembliesFromFolder(string folderPath) - { - var directory = new DirectoryInfo(folderPath); - if (!directory.Exists) return []; +// private static IEnumerable GetAssembliesFromFolder(string folderPath) +// { +// var directory = new DirectoryInfo(folderPath); +// if (!directory.Exists) return []; - var files = directory.GetFiles("*.dll"); +// var files = directory.GetFiles("*.dll"); - var assemblies = new List(); - foreach (var file in files) - { - try - { - var assembly = Assembly.LoadFrom(file.FullName); - assemblies.Add(assembly); - } - catch (Exception ex) - { - Console.WriteLine($"Error loading assembly from {file.FullName}: {ex.Message}"); - } - } +// var assemblies = new List(); +// foreach (var file in files) +// { +// try +// { +// var assembly = Assembly.LoadFrom(file.FullName); +// assemblies.Add(assembly); +// } +// catch (Exception ex) +// { +// Console.WriteLine($"Error loading assembly from {file.FullName}: {ex.Message}"); +// } +// } - return assemblies; - } - } -} +// return assemblies; +// } +// } +//} diff --git a/JiShe.CollectBus.Console/Extensions/ServiceCollections/ServiceCollectionExtensions.cs b/JiShe.CollectBus.Console/Extensions/ServiceCollections/ServiceCollectionExtensions.cs index 60231f8..dcab11f 100644 --- a/JiShe.CollectBus.Console/Extensions/ServiceCollections/ServiceCollectionExtensions.cs +++ b/JiShe.CollectBus.Console/Extensions/ServiceCollections/ServiceCollectionExtensions.cs @@ -1,52 +1,56 @@ -using JiShe.CollectBus.Core.Plugins; +using System.Reflection; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Core.Plugins; using JiShe.CollectBus.Core.Services; using JiShe.CollectBus.Protocol.Contracts.Adapters; using Microsoft.Extensions.Configuration; using TouchSocket.Core; using TouchSocket.Sockets; +using Volo.Abp.Modularity; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection { public static class ServiceCollectionExtensions { - /// - /// 添加TcpService服务。 - /// - public static IServiceCollection AddTcp(this IServiceCollection services, IConfiguration configuration) + public static void AddPluginApplications(this IServiceCollection services, string pluginPath = "") { - services.AddTcpService(config => + if (string.IsNullOrWhiteSpace(pluginPath)) { - config.SetListenIPHosts(int.Parse(configuration["TCP:ClientPort"] ?? "10500")) - //.SetTcpDataHandlingAdapter(()=>new StandardFixedHeaderDataHandlingAdapter()) - .ConfigurePlugins(a => - { - a.Add(); - a.Add(); - a.Add(); - }); - }); - return services; + pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"); + } + var assemblies = GetAssembliesFromFolder(pluginPath); + + foreach (var assembly in assemblies) + { + var applicationServiceType = assembly.GetTypes() + .FirstOrDefault(a => a.IsClass && !a.IsAbstract && typeof(AbpModule).IsAssignableFrom(a)); + services.AddApplication(applicationServiceType); + } } - - /// - /// 添加UdpService服务。 - /// - public static IServiceCollection AddUdp(this IServiceCollection services, IConfiguration configuration) + private static IEnumerable GetAssembliesFromFolder(string folderPath) { - services.AddUdpSession(config => + var directory = new DirectoryInfo(folderPath); + if (!directory.Exists) return []; + + var files = directory.GetFiles("*.dll"); + + var assemblies = new List(); + foreach (var file in files) { - config.SetBindIPHost(int.Parse(configuration["UDP:ClientPort"] ?? "10500")) - .ConfigurePlugins(a => - { - a.Add(); - a.Add(); - }) - .UseBroadcast() - .SetUdpDataHandlingAdapter(() => new NormalUdpDataHandlingAdapter()); - }); - return services; + try + { + var assembly = Assembly.LoadFrom(file.FullName); + assemblies.Add(assembly); + } + catch (Exception ex) + { + Console.WriteLine($"Error loading assembly from {file.FullName}: {ex.Message}"); + } + } + + return assemblies; } } } diff --git a/JiShe.CollectBus.Console/JiShe.CollectBus.Console.csproj b/JiShe.CollectBus.Console/JiShe.CollectBus.Console.csproj index d54ae89..50e667f 100644 --- a/JiShe.CollectBus.Console/JiShe.CollectBus.Console.csproj +++ b/JiShe.CollectBus.Console/JiShe.CollectBus.Console.csproj @@ -39,6 +39,7 @@ + @@ -47,9 +48,12 @@ - - Always - + + Always + + + Always + diff --git a/JiShe.CollectBus.Console/Program.cs b/JiShe.CollectBus.Console/Program.cs index 2c3b33a..aa194fa 100644 --- a/JiShe.CollectBus.Console/Program.cs +++ b/JiShe.CollectBus.Console/Program.cs @@ -1,7 +1,9 @@ -using Microsoft.Extensions.Configuration; +using JiShe.CollectBus.Core; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Serilog; +using Volo.Abp; namespace JiShe.CollectBus.Console { @@ -18,6 +20,7 @@ namespace JiShe.CollectBus.Console CreateHostBuilder(args).Build().Run(); + } catch (Exception ex) { @@ -52,16 +55,17 @@ namespace JiShe.CollectBus.Console lc.ReadFrom.Configuration(configuration) .ReadFrom.Services(context); }); - services.ServiceRegister() - .ModuleRegister(configuration) - .PluginServiceRegister(); - services.AddTcp(configuration); - //services.AddUdp(configuration); + services.AddApplication(); + services.AddPluginApplications(); services.AddStackExchangeRedisCache(options => { options.Configuration = configuration["RedisCache:ConnectionString"]; options.InstanceName = configuration["RedisCache:InstanceName"]; }); + + //var app = AbpApplicationFactory.Create(); + //app.Initialize(); + } } } diff --git a/JiShe.CollectBus.Core/JiSheCollectBusCoreModule.cs b/JiShe.CollectBus.Core/JiSheCollectBusCoreModule.cs new file mode 100644 index 0000000..6aa60ea --- /dev/null +++ b/JiShe.CollectBus.Core/JiSheCollectBusCoreModule.cs @@ -0,0 +1,50 @@ +using JiShe.CollectBus.Core.Plugins; +using JiShe.CollectBus.Core.Services; +using JiShe.CollectBus.EntityFrameworkCore; +using JiShe.CollectBus.RabbitMQ; +using Microsoft.Extensions.DependencyInjection; +using TouchSocket.Core; +using TouchSocket.Sockets; +using Volo.Abp; +using Volo.Abp.Modularity; + +namespace JiShe.CollectBus.Core +{ + [DependsOn(typeof(JiSheCollectBusEntityFrameworkCoreModule), + typeof(JiSheCollectBusRabbitMqModule))] + public class JiSheCollectBusCoreModule : AbpModule + { + public override async void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + context.Services.AddTcpService(config => + { + config.SetListenIPHosts(int.Parse(configuration["TCP:ClientPort"] ?? "10500")) + //.SetTcpDataHandlingAdapter(()=>new StandardFixedHeaderDataHandlingAdapter()) + .ConfigurePlugins(a => + { + a.Add(); + a.Add(); + a.Add(); + }); + }); + + context.Services.AddUdpSession(config => + { + config.SetBindIPHost(int.Parse(configuration["UDP:ClientPort"] ?? "10500")) + .ConfigurePlugins(a => + { + a.Add(); + a.Add(); + }) + .UseBroadcast() + .SetUdpDataHandlingAdapter(() => new NormalUdpDataHandlingAdapter()); + }); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + + } + } +} diff --git a/JiShe.CollectBus.Core/Plugins/TcpServicePlugin.cs b/JiShe.CollectBus.Core/Plugins/TcpServicePlugin.cs index 54cddc5..1e6133d 100644 --- a/JiShe.CollectBus.Core/Plugins/TcpServicePlugin.cs +++ b/JiShe.CollectBus.Core/Plugins/TcpServicePlugin.cs @@ -16,14 +16,16 @@ namespace JiShe.CollectBus.Core.Plugins private readonly ILogger _logger; public readonly IMongoRepository _mongoHeartbeatRepository; public readonly IMongoRepository _mongoLoginRepository; + public readonly IServiceProvider _serviceProvider; - public TcpServicePlugin(INSender nSender, ILogger logger,IMongoRepository mongoHeartbeatRepository, IMongoRepository mongoLoginRepository) + public TcpServicePlugin(INSender nSender, ILogger logger,IMongoRepository mongoHeartbeatRepository, IMongoRepository mongoLoginRepository, IServiceProvider serviceProvider) { _nSender = nSender; _logger = logger; _mongoHeartbeatRepository = mongoHeartbeatRepository; _mongoLoginRepository = mongoLoginRepository; + _serviceProvider = serviceProvider; } diff --git a/JiShe.CollectBus.EntityFrameworkCore/JiSheCollectBusEntityFrameworkCoreModule.cs b/JiShe.CollectBus.EntityFrameworkCore/JiSheCollectBusEntityFrameworkCoreModule.cs new file mode 100644 index 0000000..3b9b93e --- /dev/null +++ b/JiShe.CollectBus.EntityFrameworkCore/JiSheCollectBusEntityFrameworkCoreModule.cs @@ -0,0 +1,11 @@ +using Volo.Abp.Modularity; + +namespace JiShe.CollectBus.EntityFrameworkCore +{ + public class JiSheCollectBusEntityFrameworkCoreModule: AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + } + } +} diff --git a/JiShe.CollectBus.Host/JiShe.CollectBus.Host.csproj b/JiShe.CollectBus.Host/JiShe.CollectBus.Host.csproj index 3d18fb4..7ebd36a 100644 --- a/JiShe.CollectBus.Host/JiShe.CollectBus.Host.csproj +++ b/JiShe.CollectBus.Host/JiShe.CollectBus.Host.csproj @@ -1,32 +1,35 @@  - - net8.0 - enable - enable - + + net8.0 + enable + enable + - - - - - - - - - - - - + + + + + + + + + + + + + + - + - - - - - - - + + + + + + + + diff --git a/JiShe.CollectBus.Host/Startup.cs b/JiShe.CollectBus.Host/Startup.cs index 8cdfb2f..af72189 100644 --- a/JiShe.CollectBus.Host/Startup.cs +++ b/JiShe.CollectBus.Host/Startup.cs @@ -2,6 +2,8 @@ using Hangfire.Dashboard.BasicAuthorization; using Hangfire.HttpJob; using Hangfire.MySql; +using JiShe.CollectBus.Application; +using JiShe.CollectBus.Core; namespace JiShe.CollectBus.Host { @@ -33,11 +35,12 @@ namespace JiShe.CollectBus.Host config.UseHangfireHttpJob(); }); services.AddHangfireServer(); - services.ServiceRegister().ModuleRegister(configuration); + services.AddApplication(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { + app.InitializeApplication(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); @@ -83,6 +86,7 @@ namespace JiShe.CollectBus.Host { endpoint.MapControllers(); }); + } } diff --git a/JiShe.CollectBus.Host/appsettings.json b/JiShe.CollectBus.Host/appsettings.json index 0c7713a..e9caf9e 100644 --- a/JiShe.CollectBus.Host/appsettings.json +++ b/JiShe.CollectBus.Host/appsettings.json @@ -27,7 +27,8 @@ }, "ConnectionStrings": { - "Default": "Data Source=192.168.111.248;Port=3306;Database=JiSheCollectBus;uid=root;pwd=123456abcD;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" + //"Default": "Data Source=192.168.111.248;Port=3306;Database=JiSheCollectBus;uid=root;pwd=123456abcD;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true", + "Default": "Data Source=localhost;Port=3306;Database=JiSheCollectBus;uid=root;pwd=123456abcD;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" }, "MongoSettings": { "Connection": "mongodb://backups_admin:jishe_mongodb_backups@118.190.144.92:27037", diff --git a/JiShe.CollectBus.MongoDB/JiSheCollectBusMongoDBModule.cs b/JiShe.CollectBus.MongoDB/JiSheCollectBusMongoDBModule.cs index 335fc4d..70cfde5 100644 --- a/JiShe.CollectBus.MongoDB/JiSheCollectBusMongoDBModule.cs +++ b/JiShe.CollectBus.MongoDB/JiSheCollectBusMongoDBModule.cs @@ -1,12 +1,11 @@ -using JiShe.CollectBus.Common.Interfaces; -using JiShe.CollectBus.Common.Models; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; namespace JiShe.CollectBus.MongoDB { - public class JiSheCollectBusMongoDbModule: IJiSheModule + public class JiSheCollectBusMongoDbModule: AbpModule { - public void ConfigureServices(ServiceContext context) + public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddSingleton(); context.Services.AddSingleton(); diff --git a/JiShe.CollectBus.MongoDB/MongoBaseRepository.cs b/JiShe.CollectBus.MongoDB/MongoBaseRepository.cs index ccf2f54..740c10b 100644 --- a/JiShe.CollectBus.MongoDB/MongoBaseRepository.cs +++ b/JiShe.CollectBus.MongoDB/MongoBaseRepository.cs @@ -1,5 +1,4 @@ -using JiShe.CollectBus.Common.Extensions.DependencyInjections; -using MongoDB.Bson; +using MongoDB.Bson; using MongoDB.Driver; using System; using System.Collections.Generic; diff --git a/JiShe.CollectBus.MongoDB/MongoContext.cs b/JiShe.CollectBus.MongoDB/MongoContext.cs index f672e41..7491027 100644 --- a/JiShe.CollectBus.MongoDB/MongoContext.cs +++ b/JiShe.CollectBus.MongoDB/MongoContext.cs @@ -1,11 +1,5 @@ using Microsoft.Extensions.Configuration; using MongoDB.Driver; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using JiShe.CollectBus.Common.Extensions.DependencyInjections; namespace JiShe.CollectBus.MongoDB { diff --git a/JiShe.CollectBus.MongoDB/UnitOfWork.cs b/JiShe.CollectBus.MongoDB/UnitOfWork.cs index 9906f87..6b7b523 100644 --- a/JiShe.CollectBus.MongoDB/UnitOfWork.cs +++ b/JiShe.CollectBus.MongoDB/UnitOfWork.cs @@ -1,5 +1,4 @@ -using JiShe.CollectBus.Common.Extensions.DependencyInjections; -using MongoDB.Driver; +using MongoDB.Driver; using System; using System.Collections.Generic; using System.Linq; diff --git a/JiShe.CollectBus.Protocol.Test/JiSheCollectBusTestProtocolModule.cs b/JiShe.CollectBus.Protocol.Test/JiSheCollectBusTestProtocolModule.cs new file mode 100644 index 0000000..63a75e9 --- /dev/null +++ b/JiShe.CollectBus.Protocol.Test/JiSheCollectBusTestProtocolModule.cs @@ -0,0 +1,20 @@ +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.Modularity; + +namespace JiShe.CollectBus.Protocol.Demo +{ + public class JiSheCollectBusTestProtocolModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddKeyedSingleton("Test"); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + + } + } +} diff --git a/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs b/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs index dcff1d6..2addc56 100644 --- a/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs +++ b/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs @@ -1,24 +1,21 @@ -using JiShe.CollectBus.Common.Extensions.DependencyInjections; -using JiShe.CollectBus.MongoDB; -using JiShe.CollectBus.Protocol.Contracts.Abstracts; +using JiShe.CollectBus.Protocol.Contracts.Abstracts; using JiShe.CollectBus.Protocol.Contracts.Attributes; using JiShe.CollectBus.Protocol.Contracts.Models; -using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Logging; -using TouchSocket.Sockets; -namespace JiShe.CollectBus.Protocol.Test +namespace JiShe.CollectBus.Protocol.Demo { [ProtocolName("TestProtocol")] - public class TestProtocolPlugin : BaseProtocolPlugin, ISingletonDependency + public class TestProtocolPlugin : BaseProtocolPlugin { public TestProtocolPlugin(ILogger logger) : base(logger) { } - public override Task GetAsync() + public override async Task GetAsync() { - throw new NotImplementedException(); + var info = new ProtocolInfo("Test", "376.1", "TCP", "376.1协议", "DTS1980"); + return await Task.FromResult(info); } public override Task AnalyzeAsync(MessageReceivedEvent messageReceivedEvent, Action? sendAction = null) diff --git a/JiShe.CollectBus.Protocol/JiSheCollectBusProtocolModule.cs b/JiShe.CollectBus.Protocol/JiSheCollectBusProtocolModule.cs new file mode 100644 index 0000000..3c89027 --- /dev/null +++ b/JiShe.CollectBus.Protocol/JiSheCollectBusProtocolModule.cs @@ -0,0 +1,21 @@ +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.RabbitMQ; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.Modularity; + +namespace JiShe.CollectBus.Protocol +{ + public class JiSheCollectBusProtocolModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddKeyedSingleton("Standard"); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + + } + } +} diff --git a/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs b/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs index a47456a..9113ffe 100644 --- a/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs +++ b/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs @@ -1,17 +1,17 @@ using JiShe.CollectBus.Common.Enums; using JiShe.CollectBus.Common.Extensions; -using JiShe.CollectBus.Common.Extensions.DependencyInjections; using JiShe.CollectBus.Common.Models; using JiShe.CollectBus.Protocol.Contracts.Abstracts; using JiShe.CollectBus.Protocol.Contracts.Attributes; using JiShe.CollectBus.Protocol.Contracts.Models; using JiShe.CollectBus.RabbitMQ.Senders; using Microsoft.Extensions.Logging; +using Volo.Abp.DependencyInjection; namespace JiShe.CollectBus.Protocol { [ProtocolName("StandardProtocol")] - public class StandardProtocolPlugin(INSender nSender, ILogger logger) : BaseProtocolPlugin(logger), ISingletonDependency + public class StandardProtocolPlugin(INSender nSender, ILogger logger) : BaseProtocolPlugin(logger) { public override async Task GetAsync() { diff --git a/JiShe.CollectBus.RabbitMQ/JiSheCollectBusRabbitMqModule.cs b/JiShe.CollectBus.RabbitMQ/JiSheCollectBusRabbitMqModule.cs index 7fb927b..30061e6 100644 --- a/JiShe.CollectBus.RabbitMQ/JiSheCollectBusRabbitMqModule.cs +++ b/JiShe.CollectBus.RabbitMQ/JiSheCollectBusRabbitMqModule.cs @@ -1,19 +1,16 @@ -using JiShe.CollectBus.Common.Interfaces; -using JiShe.CollectBus.Common.Models; -using JiShe.CollectBus.RabbitMQ.Consumers; +using JiShe.CollectBus.RabbitMQ.Consumers; using MassTransit; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using System.Data; +using Volo.Abp; +using Volo.Abp.Modularity; namespace JiShe.CollectBus.RabbitMQ { - public class JiSheCollectBusRabbitMqModule: IJiSheModule + public class JiSheCollectBusRabbitMqModule: AbpModule { - public void ConfigureServices(ServiceContext context) + public override void ConfigureServices(ServiceConfigurationContext context) { - var configuration = context.Configuration; + var configuration = context.Services.GetConfiguration(); context.Services.AddMassTransit(x => { x.AddConsumer(cfg => @@ -51,7 +48,7 @@ namespace JiShe.CollectBus.RabbitMQ }); // 消息接收队列 - cfg.ReceiveEndpoint(configuration["MQ:Queue:Received"] ?? string.Empty,configurator => + cfg.ReceiveEndpoint(configuration["MQ:Queue:Received"] ?? string.Empty, configurator => { configurator.ConfigureConsumeTopology = false; configurator.Consumer(c); @@ -81,5 +78,9 @@ namespace JiShe.CollectBus.RabbitMQ }); }); } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + } } } diff --git a/JiShe.CollectBus.RabbitMQ/Senders/NSender.cs b/JiShe.CollectBus.RabbitMQ/Senders/NSender.cs index 62e15f9..9c062ad 100644 --- a/JiShe.CollectBus.RabbitMQ/Senders/NSender.cs +++ b/JiShe.CollectBus.RabbitMQ/Senders/NSender.cs @@ -1,6 +1,6 @@ using MassTransit; using Microsoft.Extensions.Configuration; -using JiShe.CollectBus.Common.Extensions.DependencyInjections; +using Volo.Abp.DependencyInjection; namespace JiShe.CollectBus.RabbitMQ.Senders {