使用新框架与技术代替旧框架与技术,实现涂装车间后道标签扫码程序

This commit is contained in:
2025-05-14 13:32:38 +08:00
parent 91cd88e285
commit 289e1e84ec
243 changed files with 4368 additions and 49365 deletions

View File

@@ -0,0 +1,52 @@
using System;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Prism.Ioc;
using RIZO_Application.Infrastructure.CustomAttribute;
namespace RIZO_Application.Core.Infrastructure.CustomExtensions
{
public static class ContainerRegistryExtensions
{
public static void AutoRegisterServices(this IContainerRegistry containerRegistry, Assembly assembly)
{
var types = assembly.GetTypes()
.Where(t => t.IsClass && !t.IsAbstract && t.GetCustomAttribute<AppServiceAttribute>() != null);
foreach (var type in types)
{
var attribute = type.GetCustomAttribute<AppServiceAttribute>();
var serviceType = attribute.ServiceType ?? type; // 默认注册为自身
switch (attribute.Lifetime)
{
case RIZO_Application.Infrastructure.CustomAttribute.ServiceLifetime.Singleton:
containerRegistry.RegisterSingleton(serviceType, type);
break;
case RIZO_Application.Infrastructure.CustomAttribute.ServiceLifetime.Scoped:
containerRegistry.RegisterScoped(serviceType, type);
break;
default: // Transient
containerRegistry.Register(serviceType, type);
break;
}
}
}
public static void AutoRegisterViews(this IContainerRegistry containerRegistry, Assembly assembly)
{
var viewTypes = assembly.GetTypes()
.Where(t => t.IsClass && !t.IsAbstract && t.GetCustomAttribute<AutoRegisterViewAttribute>() != null);
foreach (var viewType in viewTypes)
{
var attribute = viewType.GetCustomAttribute<AutoRegisterViewAttribute>();
string viewName = attribute?.ViewName ?? viewType.Name; // 默认使用类名
containerRegistry.RegisterForNavigation(viewType, viewName);
}
}
}
}