generated from wenjy/Sln.Iot
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.
74 lines
2.5 KiB
C#
74 lines
2.5 KiB
C#
using System.Reflection;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Sln.Iot.Config;
|
|
using Sln.Iot.Repository;
|
|
using Sln.Iot.Serilog;
|
|
using TouchSocket.Sockets;
|
|
|
|
namespace Sln.Iot
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
internal class Program
|
|
{
|
|
public static IServiceProvider? ServiceProvider = null;
|
|
|
|
static async Task Main(string[] args)
|
|
{
|
|
var services = new ServiceCollection();
|
|
ConfigureServices(services);
|
|
ServiceProvider = services.BuildServiceProvider();
|
|
ServiceProvider.UseSerilogExtensions();
|
|
|
|
var appConfig = ServiceProvider.GetService<AppConfig>();
|
|
var log = ServiceProvider.GetService<SerilogHelper>();
|
|
log.Info($"系统启动成功,日志存放位置:{appConfig.logPath}");
|
|
|
|
await Task.Delay(-1);
|
|
}
|
|
|
|
private static void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddSingleton<AppConfig>(provider =>
|
|
{
|
|
var configurationBuilder = new ConfigurationBuilder()
|
|
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
|
IConfiguration configuration = configurationBuilder.Build();
|
|
var ap = configuration.GetSection("AppConfig").Get<AppConfig>();
|
|
return ap;
|
|
});
|
|
|
|
//services.AddSingleton<TcpClient>(provider =>
|
|
//{
|
|
// TcpClient tcpClient = new TcpClient();
|
|
// tcpClient.Setup(new TouchSocketConfig()
|
|
// .SetRemoteIPHost("127.0.0.1:6000")
|
|
// .ConfigureContainer(a =>
|
|
// {
|
|
// a.AddConsoleLogger();
|
|
// }));
|
|
// tcpClient.Connect();
|
|
// return tcpClient;
|
|
//});
|
|
|
|
Assembly[] assemblies =
|
|
{
|
|
Assembly.LoadFrom("Sln.Iot.Repository.dll"),
|
|
Assembly.LoadFrom("Sln.Iot.Socket.dll"),
|
|
Assembly.LoadFrom("Sln.Iot.Common.dll"),
|
|
Assembly.LoadFrom("Sln.Iot.Business.dll"),
|
|
};
|
|
|
|
services.Scan(scan => scan.FromAssemblies(assemblies)
|
|
.AddClasses()
|
|
.AsImplementedInterfaces()
|
|
.AsSelf()
|
|
.WithSingletonLifetime());
|
|
|
|
services.AddSingleton(typeof(SerilogHelper));
|
|
}
|
|
}
|
|
} |