Repository navigation
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
45 lines (40 loc) · 1.8 KB
/
Copy pathServiceCollectionExtensions.cs
File metadata and controls
45 lines (40 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// filepath: Application/ServiceCollectionExtensions.cs
using CookingTime.Application.Abstractions;
using CookingTime.Application.Services;
using CookingTime.Domain.Abstractions;
using CookingTime.Infrastructure.Configuration;
using CookingTime.Infrastructure.Meals;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace CookingTime.Application;
/// <summary>
/// Single source of truth for the CookingTime composition root.
/// Both the Blazor WebAssembly client (<c>Program.cs</c>) and the
/// Phase 5 test-only host (<c>tests/CookingTime.IntegrationTests</c>)
/// call <see cref="AddCookingTime"/>; any new application service
/// belongs here, not in either entry point.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Registers the production CookingTime services: options binding
/// from <paramref name="configuration"/>, the meal factory, and the
/// cooking-time calculator. Pure composition — no Web, no logging.
/// </summary>
public static IServiceCollection AddCookingTime(
this IServiceCollection services,
IConfiguration configuration)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configuration);
services.Configure<MealCatalogOptions>(
configuration.GetSection(MealCatalogOptions.SectionName));
services.Configure<ProductInfoOptions>(
configuration.GetSection(ProductInfoOptions.SectionName));
// Stateless; WASM has no per-request scope and the test host
// is a single-process integration fixture. Safe as Singleton.
services.AddSingleton<IMealFactory, MealFactory>();
services.AddSingleton<ICookingTimeCalculator, CookingTimeCalculator>();
return services;
}
}