using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TeamUp.SharedKernel.Modularity;
namespace TeamUp.Bootstrap;
public static class TeamUpModuleExtensions
{
/// Runs every module's Register. Called by BOTH hosts.
public static IServiceCollection AddTeamUpModules(
this IServiceCollection services,
IConfiguration configuration)
{
foreach (var module in ModuleCatalog.All)
{
module.Register(services, configuration);
}
return services;
}
/// Runs every module's MapEndpoints. Called by the WEB host only.
public static IEndpointRouteBuilder MapTeamUpModules(this IEndpointRouteBuilder endpoints)
{
foreach (var module in ModuleCatalog.All)
{
module.MapEndpoints(endpoints);
}
return endpoints;
}
/// Runs RegisterWorker for modules with background services. WORKER host only.
public static IServiceCollection AddTeamUpWorkerServices(
this IServiceCollection services,
IConfiguration configuration)
{
foreach (var module in ModuleCatalog.All)
{
if (module is IWorkerModule workerModule)
{
workerModule.RegisterWorker(services, configuration);
}
}
return services;
}
}