39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using XPrintServer.Business.Services.Interface;
|
|
|
|
namespace XPrintServer.Business.Extensions
|
|
{
|
|
|
|
public static class ServicesExtension
|
|
{
|
|
/// <summary>
|
|
/// Services配置
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="configuration"></param>
|
|
public static void AddServices(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
var businessType = typeof(IBusinessService);
|
|
Assembly? businessAssembly = Assembly.GetAssembly(businessType);
|
|
if (businessAssembly != null)
|
|
{
|
|
var types = businessAssembly.GetTypes();
|
|
foreach (var t in types)
|
|
{
|
|
if (!t.IsInterface && t.GetInterface(businessType.Name) != null)
|
|
{
|
|
services.AddScoped(t);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|