NadekoBot/src/NadekoBot/Services/Database/UnitOfWork.cs

67 lines
2.3 KiB
C#
Raw Normal View History

using NadekoBot.Services.Database.Repositories;
using NadekoBot.Services.Database.Repositories.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Services.Database
{
public class UnitOfWork : IUnitOfWork
{
private NadekoContext _context;
private IQuoteRepository _quotes;
public IQuoteRepository Quotes => _quotes ?? (_quotes = new QuoteRepository(_context));
2016-08-26 17:25:54 +00:00
private IGuildConfigRepository _guildConfigs;
public IGuildConfigRepository GuildConfigs => _guildConfigs ?? (_guildConfigs = new GuildConfigRepository(_context));
2016-08-24 17:04:24 +00:00
private IDonatorsRepository _donators;
public IDonatorsRepository Donators => _donators ?? (_donators = new DonatorsRepository(_context));
2016-08-25 17:23:47 +00:00
private IClashOfClansRepository _clashOfClans;
public IClashOfClansRepository ClashOfClans => _clashOfClans ?? (_clashOfClans = new ClashOfClansRepository(_context));
2016-08-25 22:05:29 +00:00
private IReminderRepository _reminders;
public IReminderRepository Reminders => _reminders ?? (_reminders = new ReminderRepository(_context));
2016-08-26 17:25:54 +00:00
private ISelfAssignedRolesRepository _selfAssignedRoles;
public ISelfAssignedRolesRepository SelfAssignedRoles => _selfAssignedRoles ?? (_selfAssignedRoles = new SelfAssignedRolesRepository(_context));
private IBotConfigRepository _botConfig;
public IBotConfigRepository BotConfig => _botConfig ?? (_botConfig = new BotConfigRepository(_context));
2016-08-28 20:59:12 +00:00
private IRepeaterRepository _repeaters;
public IRepeaterRepository Repeaters => _repeaters ?? (_repeaters = new RepeaterRepository(_context));
public UnitOfWork(NadekoContext context)
{
2016-08-24 19:38:17 +00:00
_context = context;
}
2016-08-24 13:29:01 +00:00
public int Complete() =>
_context.SaveChanges();
public Task<int> CompleteAsync() =>
_context.SaveChangesAsync();
private bool disposed = false;
protected void Dispose(bool disposing)
{
if (!this.disposed)
if (disposing)
_context.Dispose();
this.disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}