//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); // 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(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 []; // 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}"); // } // } // return assemblies; // } // } //}