.NET 10 solution for Ping, a Discord style chat app: Domain, Application and Infrastructure projects plus the Api host. SignalR for chat and presence, LiveKit for call tokens, EF Core on Postgres, S3 compatible storage for attachments, and OIDC auth shared with the Musify Zitadel instance. Includes the Compose stack for local development.
32 lines
1.3 KiB
C#
32 lines
1.3 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
using Ping.Application.Contracts;
|
|
using Ping.Infrastructure.Configuration;
|
|
|
|
namespace Ping.Infrastructure.Persistence
|
|
{
|
|
public static class DatabaseDependencyInjection
|
|
{
|
|
public static IServiceCollection AddDatabase(this IServiceCollection serviceDescriptors, IConfiguration configuration)
|
|
{
|
|
serviceDescriptors
|
|
.AddOptionsWithValidateOnStart<DatabaseConfiguration>()
|
|
.Bind(configuration.GetRequiredSection(DatabaseConfiguration.SectionName))
|
|
.ValidateDataAnnotations();
|
|
|
|
serviceDescriptors.AddSingleton(serviceProvider =>
|
|
serviceProvider.GetRequiredService<IOptions<DatabaseConfiguration>>().Value);
|
|
|
|
serviceDescriptors.AddSingleton<AuditableEntityInterceptor>();
|
|
|
|
serviceDescriptors.AddDbContext<Database>((serviceProvider, options) =>
|
|
options.AddInterceptors(serviceProvider.GetRequiredService<AuditableEntityInterceptor>()));
|
|
|
|
serviceDescriptors.AddScoped<IDatabase>(serviceProvider => serviceProvider.GetRequiredService<Database>());
|
|
|
|
return serviceDescriptors;
|
|
}
|
|
}
|
|
}
|