using Skcks.Study.WebProject.HelloWorld;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Modularity;

namespace Skcks.Study.WebProject.HelloAbpWeb;

[DependsOn(typeof(AbpAspNetCoreMvcModule))]
public class AppModule: AbpModule
{
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        Console.WriteLine("PreConfigureServices");
    }

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        // 手动注册
        context.Services.AddTransient<HelloWorldService>();
        Console.WriteLine("ConfigureServices");
    }

    public override void PostConfigureServices(ServiceConfigurationContext context)
    {
        Console.WriteLine("PostConfigureServices");
    }

    public override void OnPreApplicationInitialization(ApplicationInitializationContext context)
    {
        Console.WriteLine("OnPreApplicationInitialization");
    }
    
    
    public override void OnApplicationInitialization(ApplicationInitializationContext context)
    {
        var app = context.GetApplicationBuilder();
        var env = context.GetEnvironment();
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseRouting();
        app.UseConfiguredEndpoints();
    }
    
    public override void OnPostApplicationInitialization(ApplicationInitializationContext context)
    {
        Console.WriteLine("OnPostApplicationInitialization");
        var helloWorldService = context.ServiceProvider.GetService<HelloWorldService>();
        helloWorldService?.Run();
    }

    public override void OnApplicationShutdown(ApplicationShutdownContext context)
    {
        Console.WriteLine("OnApplicationShutdown");
    }
}