using Aucma.Core.SheetMetalTasks; using Aucma.Core.TemperatureTask; using Microsoft.Extensions.DependencyInjection; using System; using System.Linq; using System.Reflection; namespace Admin.Core.Extensions { /// /// 启动测温定时服务 /// public static class TemperatureTaskSetup { public static void AddTemperatureTaskSetup(this IServiceCollection services) { services.AddSingleton(); var baseType = typeof(IAucamTemperatureMeasurementService); var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; var referencedAssemblies = System.IO.Directory.GetFiles(path, "Aucma.Core.TemperatureTask.dll").Select(Assembly.LoadFrom).ToArray(); var types = referencedAssemblies .SelectMany(a => a.DefinedTypes) .Select(type => type.AsType()) .Where(x => x != baseType && baseType.IsAssignableFrom(x)).ToArray(); var implementTypes = types.Where(x => x.IsClass).ToArray(); foreach (var implementType in implementTypes) { services.AddTransient(implementType); } } } }