You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Aucma.Scada/Aucma.Scada.Business/RegisterServices.cs

75 lines
2.5 KiB
C#

using HighWayIot.Repository;
using HighWayIot.Repository.service;
using HighWayIot.Repository.service.Impl;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Aucma.Scada.Business
{
/// <summary>
/// 注册服务
/// </summary>
internal sealed class RegisterServices
{
#region 单例实现
private static readonly Lazy<RegisterServices> lazy = new Lazy<RegisterServices>(() => new RegisterServices());
public static RegisterServices Instance
{
get
{
return lazy.Value;
}
}
#endregion
#region 接口引用
private readonly IServiceProvider _serviceProvider;
#endregion
private RegisterServices()
{
var services = new ServiceCollection();
#region 自动注册服务
// 自动注册服务
//Assembly.GetExecutingAssembly()
// .GetTypes()
// .Where(t => t.IsClass && !t.IsAbstract)
// .Where(t => t.GetInterfaces().Any())
// .ToList()
// .ForEach(t => services.AddSingleton(t.GetInterfaces().FirstOrDefault(), t));
#endregion
AddSingletonServices(services);
_serviceProvider = services.BuildServiceProvider();
}
/// <summary>
/// 注册服务
/// </summary>
/// <param name="services"></param>
private void AddSingletonServices(IServiceCollection services)
{
services.AddSingleton<IBaseBomInfoService, BaseBomInfoServiceImpl>();
services.AddSingleton<IBaseSpaceDetailService, BaseSpaceDetailServiceImpl>();
services.AddSingleton<IBaseSpaceInfoService, BaseSpaceInfoServiceImpl>();
services.AddSingleton<IExecutePlanInfoService, ExecutePlanInfoServiceImpl>();
services.AddSingleton<IProductPlanInfoService, ProductPlanInfoServiceImpl>();
services.AddSingleton<IRealTaskInfoService, RealTaskInfoServiceImpl>();
services.AddSingleton<ISysUserInfoService, SysUserInfoServiceImpl>();
services.AddSingleton<IRecordInStoreService, RecordInStoreServiceImpl>();
services.AddSingleton<IRecordOutStoreService, RecordOutStoreServiceImpl>();
services.AddSingleton<IRecordProductfinishService, RecordProductfinishServiceImpl>();
}
public T GetService<T>()
{
var service = _serviceProvider.GetService<T>();
return service;
}
}
}