using Admin.Core.Common;
using Admin.Core.Extensions;
using Admin.Core.IRepository;
using Admin.Core.IService;
using Admin.Core.IService.ISys;
using Admin.Core.Model;
using Admin.Core.Repository;
using Admin.Core.Service;
using Admin.Core.Socket;
using Admin.Core.Tasks;
using Aucma.Core.DataCollector;
using Aucma.Core.RunPlc;
using Aucma.Core.Scanner;
using Aucma.Core.ScannerGun;
using Autofac;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Sockets;
using System.Text;
namespace Aucma.Core.CodeBinding
{
///
/// Startup
///
public class Startup
{
///
/// Startup
///
///
public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
Configuration = configuration;
Env = env;
}
///
/// IConfiguration
///
public IConfiguration Configuration { get; }
///
/// 环境信息:开发/生产
///
public IWebHostEnvironment Env { get; }
///
/// This method gets called by the runtime. Use this method to add services to the container.
///
///
public void ConfigureServices(IServiceCollection services)
{
//Appsettings
services.AddSingleton(new Appsettings(Configuration));
//日志文件目录
services.AddSingleton(new LogLock(Env.ContentRootPath));
//Memory缓存
services.AddMemoryCacheSetup();
//Sqlsugar数据库模型查询
services.AddSqlsugarSetup();
//AutoMapper
services.AddAutoMapperSetup();
//注册业务服务
AddServices(services);
//socket连接扫码器
services.AddTouchSocketSetup();
//扫码器
// services.AddScannerSetup();
// 扫码枪
// services.AddScannerGunSetup();
//任务调度
services.AddJobSetup();
//PLC
services.AddPlcSetup();
//支持编码大全 例如:支持 System.Text.Encoding.GetEncoding("GB2312") System.Text.Encoding.GetEncoding("GB18030")
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
///
/// 注意在Program.CreateHostBuilder,添加Autofac服务工厂
///
///
public void ConfigureContainer(ContainerBuilder builder)
{
builder.RegisterModule(new AutofacModuleRegister());
builder.RegisterModule();
}
///
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
///
///
///
public void Configure(IApplicationBuilder app, IRunPlcService runPlcService, ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter, ITouchSocketService socket) // ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter,IScannerService scannerService,
{
// 使用静态文件
app.UseStaticFiles();
// 然后是授权中间件
//app.UseAuthorization();
//开启扫码服务
// app.UseScannerMildd(scannerService);
//开启扫码枪服务
// app.UseScannerGunMildd(scannerGunService);
// 开启QuartzNetJob调度服务
app.UseQuartzJobMildd(tasksQzService, schedulerCenter);
//PLC
app.UsePlcMildd(runPlcService);
// Socket连接扫码器
app.UseTouchSocketMildd(socket);
// 集存库泡后库用电采集,报警采集
app.UseDataCollectorExtensions();
}
#region 注册服务
///
/// 注册服务
///
///
private static void AddServices(IServiceCollection services)
{
#region 注册服务
//services.AddScoped();
//services.AddScoped();
//services.AddScoped, BaseRepository>();
//services.AddSingleton, BaseService>();
#endregion
}
#endregion
}
}