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.7 KiB
C#
74 lines
2.7 KiB
C#
using System.Reflection;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NeoSmart.Caching.Sqlite;
|
|
using Sln.Imm.Daemon.Cache;
|
|
using Sln.Imm.Daemon.Config;
|
|
using Sln.Imm.Daemon.Repository;
|
|
using Sln.Imm.Daemon.Serilog;
|
|
using ZiggyCreatures.Caching.Fusion;
|
|
using ZiggyCreatures.Caching.Fusion.Serialization.NewtonsoftJson;
|
|
|
|
namespace Sln.Imm.Daemon
|
|
{
|
|
internal class Program
|
|
{
|
|
public static IServiceProvider? ServiceProvider = null;
|
|
|
|
static void 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}");
|
|
|
|
Task.Delay(-1).Wait();
|
|
}
|
|
|
|
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;
|
|
});
|
|
|
|
Assembly[] assemblies =
|
|
{
|
|
Assembly.LoadFrom("Sln.Imm.Daemon.Common.dll"),
|
|
Assembly.LoadFrom("Sln.Imm.Daemon.Repository.dll"),
|
|
Assembly.LoadFrom("Sln.Imm.Daemon.Cache.dll"),
|
|
// Assembly.LoadFrom("Sln.Iot.Socket.dll"),
|
|
// Assembly.LoadFrom("Sln.Iot.Business.dll"),
|
|
};
|
|
|
|
services.Scan(scan => scan.FromAssemblies(assemblies)
|
|
.AddClasses()
|
|
.AsImplementedInterfaces()
|
|
.AsSelf()
|
|
.WithSingletonLifetime());
|
|
|
|
services.AddSingleton(typeof(SerilogHelper));
|
|
|
|
services.AddSqlSugarSetup();
|
|
|
|
services.AddFusionCache()
|
|
.WithSerializer(
|
|
new FusionCacheNewtonsoftJsonSerializer()
|
|
)
|
|
.WithDistributedCache(
|
|
new SqliteCache(new SqliteCacheOptions
|
|
{
|
|
CachePath = "/Users/wenxiansheng/Public/WorkSpace/Mesnac/项目资料/澳柯玛注塑车间MES项目/数据缓存/FusionCache.db"
|
|
}));
|
|
}
|
|
}
|
|
} |