38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using back.context;
|
|
using back.Options;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace back.ServicesExtensions;
|
|
|
|
public static partial class ServicesExtensions
|
|
{
|
|
private static IServiceCollection AddDatabaseContexts(this IServiceCollection services)
|
|
{
|
|
services
|
|
.AddContext<EventContext>()
|
|
.AddContext<GalleryContext>()
|
|
.AddContext<PersonContext>()
|
|
.AddContext<PhotoContext>()
|
|
.AddContext<TagContext>()
|
|
.AddContext<UserContext>()
|
|
;
|
|
|
|
return services;
|
|
}
|
|
private static IServiceCollection AddContext<T>(this IServiceCollection services)
|
|
where T : DbContext
|
|
{
|
|
var config = services
|
|
.BuildServiceProvider()
|
|
.GetRequiredService<IOptionsSnapshot<DatabaseConfig>>()
|
|
.Get(DatabaseConfig.DataStorage);
|
|
|
|
services.AddDbContext<T>(options =>
|
|
{
|
|
options.UseDatabaseConfig(config);
|
|
});
|
|
return services;
|
|
}
|
|
}
|