2024-02-21 02:17:33 +01:00
|
|
|
using InkForge.Data;
|
|
|
|
|
using InkForge.Desktop.Data.Options;
|
|
|
|
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-02-16 02:23:58 +01:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
namespace InkForge.Desktop.Models;
|
|
|
|
|
|
2024-02-21 02:17:33 +01:00
|
|
|
public sealed class Workspace : IDisposable
|
2024-02-16 02:23:58 +01:00
|
|
|
{
|
2024-02-21 02:17:33 +01:00
|
|
|
private readonly IDbContextFactory<NoteDbContext> _dbContextFactory;
|
|
|
|
|
private bool _disposedValue;
|
|
|
|
|
private IServiceScope? _scope;
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; } = default!;
|
|
|
|
|
|
|
|
|
|
public LocalWorkspaceOptions Options { get; set; } = default!;
|
|
|
|
|
|
|
|
|
|
public IServiceProvider Services => _scope!.ServiceProvider;
|
|
|
|
|
|
|
|
|
|
public Workspace(IServiceScope scope)
|
|
|
|
|
{
|
|
|
|
|
_scope = scope;
|
|
|
|
|
_dbContextFactory = Services.GetRequiredService<IDbContextFactory<NoteDbContext>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(disposing: true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (!_disposedValue)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
_scope!.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_scope = null;
|
|
|
|
|
_disposedValue = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-16 02:23:58 +01:00
|
|
|
}
|