|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using SlnMesnac.Config;
|
|
|
|
|
using SlnMesnac.Common;
|
|
|
|
|
using SlnMesnac.Quartz;
|
|
|
|
|
using SlnMesnac.Repository;
|
|
|
|
|
using SlnMesnac.Plc;
|
|
|
|
|
using SlnMesnac.Serilog;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Autofac;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using SlnMesnac.Mqtt;
|
|
|
|
|
using SlnMesnac.Rfid;
|
|
|
|
|
using SlnMesnac.TouchSocket;
|
|
|
|
|
|
|
|
|
|
namespace SlnMesnac.WPF
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services"></param>
|
|
|
|
|
[Obsolete]
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddControllers();
|
|
|
|
|
|
|
|
|
|
//注册AppConfig
|
|
|
|
|
services.AddSingleton<AppConfig>(provider =>
|
|
|
|
|
{
|
|
|
|
|
var configuration = provider.GetService<IConfiguration>();
|
|
|
|
|
return configuration.GetSection("AppConfig").Get<AppConfig>();
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//注册通用类
|
|
|
|
|
services.AddCommonSetup();
|
|
|
|
|
|
|
|
|
|
//注册ORM
|
|
|
|
|
services.AddSqlSugarSetup();
|
|
|
|
|
|
|
|
|
|
//注册Quartz
|
|
|
|
|
//services.AddQuartzSetUp();
|
|
|
|
|
|
|
|
|
|
//注册PLC
|
|
|
|
|
services.AddPlcSetup();
|
|
|
|
|
|
|
|
|
|
//注册MQTT
|
|
|
|
|
services.AddMqttSetup();
|
|
|
|
|
|
|
|
|
|
//注册TouchSocket
|
|
|
|
|
services.AddTouchSocketSetup();
|
|
|
|
|
|
|
|
|
|
//注册RFID
|
|
|
|
|
services.AddRfidSetup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ConfigureContainer(ContainerBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(Repository<>));
|
|
|
|
|
RegisterImplementations(builder, typeof(Repository<>).Assembly);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 自动注入接口实现
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="builder"></param>
|
|
|
|
|
/// <param name="assembly"></param>
|
|
|
|
|
private static void RegisterImplementations(ContainerBuilder builder, Assembly assembly)
|
|
|
|
|
{
|
|
|
|
|
//自动注入仓储层的接口实现类
|
|
|
|
|
var types = assembly.GetTypes()
|
|
|
|
|
.Where(t => t.IsClass && !t.IsAbstract && !t.IsGenericType)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var type in types)
|
|
|
|
|
{
|
|
|
|
|
var interfaces = type.GetInterfaces();
|
|
|
|
|
|
|
|
|
|
foreach (var @interface in interfaces)
|
|
|
|
|
{
|
|
|
|
|
builder.RegisterType(type).As(@interface);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="app"></param>
|
|
|
|
|
/// <param name="env"></param>
|
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
|
{
|
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//启用Serilog中间件
|
|
|
|
|
app.UseSerilogExtensions();
|
|
|
|
|
|
|
|
|
|
//初始化PLC中间件
|
|
|
|
|
app.UsePlcExtensions();
|
|
|
|
|
|
|
|
|
|
//初始化RFID中间件
|
|
|
|
|
app.UseRfidExtensions();
|
|
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
|
{
|
|
|
|
|
endpoints.MapControllers();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|