-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
36 lines (31 loc) · 1.32 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
36 lines (31 loc) · 1.32 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
using eduHub.Application.Interfaces.Buildings;
using eduHub.Application.Interfaces.Rooms;
using eduHub.Application.Interfaces.Reservations;
using eduHub.Application.Interfaces.Users;
using eduHub.Infrastructure.Persistence;
using eduHub.Infrastructure.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace eduHub.Infrastructure;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddInfrastructure(
this IServiceCollection services,
IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString("DefaultConnection");
// if (string.IsNullOrWhiteSpace(connectionString))
// throw new InvalidOperationException("ConnectionStrings:DefaultConnection is not configured.");
services.AddDbContext<AppDbContext>(options =>
{
if (!string.IsNullOrWhiteSpace(connectionString))
options.UseNpgsql(connectionString);
});
services.AddScoped<IBuildingService, BuildingService>();
services.AddScoped<IRoomService, RoomService>();
services.AddScoped<IReservationService, ReservationService>();
services.AddScoped<IUserService, UserService>();
return services;
}
}