39 lines
1.7 KiB
C#
39 lines
1.7 KiB
C#
using Microsoft.Extensions.Options;
|
|
using NeonSprawl.Server.Game.Skills;
|
|
|
|
namespace NeonSprawl.Server.Game.Factions;
|
|
|
|
/// <summary>DI registration for the fail-fast faction catalog (NEO-134).</summary>
|
|
public static class FactionCatalogServiceCollectionExtensions
|
|
{
|
|
/// <summary>Binds <see cref="ContentPathsOptions"/> and registers <see cref="FactionDefinitionCatalog"/> and <see cref="IFactionDefinitionRegistry"/> as singletons.</summary>
|
|
public static IServiceCollection AddFactionDefinitionCatalog(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddOptions<ContentPathsOptions>()
|
|
.Bind(configuration.GetSection(ContentPathsOptions.SectionName));
|
|
|
|
services.AddSingleton<FactionDefinitionCatalog>(sp =>
|
|
{
|
|
var hostEnv = sp.GetRequiredService<IHostEnvironment>();
|
|
var opts = sp.GetRequiredService<IOptions<ContentPathsOptions>>().Value;
|
|
var logger = sp.GetRequiredService<ILoggerFactory>()
|
|
.CreateLogger("NeonSprawl.Server.Game.Factions.FactionCatalog");
|
|
|
|
var factionsDir = FactionCatalogPathResolution.ResolveFactionsDirectory(
|
|
opts.FactionsDirectory,
|
|
hostEnv.ContentRootPath);
|
|
var schemaPath = FactionCatalogPathResolution.ResolveFactionDefSchemaPath(
|
|
factionsDir,
|
|
opts.FactionDefSchemaPath,
|
|
hostEnv.ContentRootPath);
|
|
|
|
return FactionDefinitionCatalogLoader.Load(factionsDir, schemaPath, logger);
|
|
});
|
|
|
|
services.AddSingleton<IFactionDefinitionRegistry>(sp =>
|
|
new FactionDefinitionRegistry(sp.GetRequiredService<FactionDefinitionCatalog>()));
|
|
|
|
return services;
|
|
}
|
|
}
|