using Microsoft.Extensions.Configuration;
using Serilog;
using Volo.Abp.Modularity.PlugIns;

namespace JiShe.CollectBus.Host;

/// <summary>
/// Program
/// </summary>
public class Program
{
    /// <summary>
    /// Main
    /// </summary>
    /// <param name="args"></param>
    /// <returns></returns>
    public static async Task Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);
        builder.Host.UseContentRoot(Directory.GetCurrentDirectory())
            .UseSerilog((context, loggerConfiguration) =>
            {
                loggerConfiguration.ReadFrom.Configuration(context.Configuration);
            })
            .UseAutofac();
        var configuration = builder.Configuration;
        await builder.AddApplicationAsync<CollectBusHostModule>(options =>
        {
            options.PlugInSources.AddFolder((configuration["PlugInFolder"].IsNullOrWhiteSpace()? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"): configuration["PlugInFolder"]) ?? string.Empty);
        });
        var app = builder.Build();
        await app.InitializeApplicationAsync();
        await app.RunAsync();
    }
}