mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-08-16 21:31:45 +02:00
.config
.run
.workdir
Agent
Common
Docker
Server
Phantom.Server
Phantom.Server.Database
Converters
Entities
Factories
ApplicationDbContext.cs
DatabaseProvider.cs
Phantom.Server.Database.csproj
Phantom.Server.Database.Postgres
Phantom.Server.Rpc
Phantom.Server.Services
Phantom.Server.Web
Phantom.Server.Web.Bootstrap
Phantom.Server.Web.Components
Utils
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
PhantomPanel.sln
global.json
31 lines
737 B
C#
31 lines
737 B
C#
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Phantom.Server.Database;
|
|
|
|
public sealed class DatabaseProvider {
|
|
private readonly IServiceScopeFactory serviceScopeFactory;
|
|
|
|
public DatabaseProvider(IServiceScopeFactory serviceScopeFactory) {
|
|
this.serviceScopeFactory = serviceScopeFactory;
|
|
}
|
|
|
|
public Scope CreateScope() {
|
|
return new Scope(serviceScopeFactory.CreateScope());
|
|
}
|
|
|
|
public readonly struct Scope : IDisposable {
|
|
private readonly IServiceScope scope;
|
|
|
|
public ApplicationDbContext Ctx { get; }
|
|
|
|
internal Scope(IServiceScope scope) {
|
|
this.scope = scope;
|
|
this.Ctx = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
|
}
|
|
|
|
public void Dispose() {
|
|
scope.Dispose();
|
|
}
|
|
}
|
|
}
|