using Admin.Core.Common;
using Admin.Core.Extensions;
using Admin.Core.Extensions.Middlewares;
using Aucma.Core.RunPlc;
using Aucma.Core.Tasks;
using Aucma.Core.TemperatureTask;
using Autofac;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Text;
namespace Aucam.Core.PerfusionService
{
///
/// 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);
//PLC
services.AddPlcSetup();
//灌注读取服务
services.AddAucmaTaskSetup();
//支持编码大全 例如:支持 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, IAucamTaskService aucamTaskService, IRunPlcService runPlcService)
{
// 使用静态文件
app.UseStaticFiles();
//PLC
app.UsePlcMildd(runPlcService);
// 注入灌注读取中间件
app.AucmaTaskMildds(aucamTaskService);
}
#region 注册服务
///
/// 注册服务
///
///
private static void AddServices(IServiceCollection services)
{
#region 注册服务
//services.AddScoped();
//services.AddScoped();
//services.AddScoped, BaseRepository>();
//services.AddSingleton, BaseService>();
#endregion
}
#endregion
}
}