back photo + event tags and persons
This commit is contained in:
37
back/ServicesExtensions/DatabaseContexts.cs
Normal file
37
back/ServicesExtensions/DatabaseContexts.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user