using HighWayIot.Repository;
using HighWayIot.Repository.service;
using HighWayIot.Repository.service.Impl;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Aucma.Scada.Business
{
///
/// 注册服务
///
public sealed class RegisterServices
{
#region 单例实现
private static readonly Lazy lazy = new Lazy(() => 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();
}
///
/// 注册服务
///
///
private void AddSingletonServices(IServiceCollection services)
{
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
}
public T GetService()
{
var service = _serviceProvider.GetService();
return service;
}
}
}