NadekoBot/NadekoBot.Core/Services/Database/UnitOfWork.cs

94 lines
3.9 KiB
C#
Raw Normal View History

using NadekoBot.Services.Database.Repositories;
using NadekoBot.Services.Database.Repositories.Impl;
using System;
using System.Threading.Tasks;
namespace NadekoBot.Services.Database
{
public class UnitOfWork : IUnitOfWork
{
public NadekoContext _context { get; }
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));
private ICurrencyRepository _currency;
public ICurrencyRepository Currency => _currency ?? (_currency = new CurrencyRepository(_context));
private ICurrencyTransactionsRepository _currencyTransactions;
public ICurrencyTransactionsRepository CurrencyTransactions => _currencyTransactions ?? (_currencyTransactions = new CurrencyTransactionsRepository(_context));
2016-09-04 13:11:02 +00:00
private IUnitConverterRepository _conUnits;
public IUnitConverterRepository ConverterUnits => _conUnits ?? (_conUnits = new UnitConverterRepository(_context));
private IMusicPlaylistRepository _musicPlaylists;
public IMusicPlaylistRepository MusicPlaylists => _musicPlaylists ?? (_musicPlaylists = new MusicPlaylistRepository(_context));
private ICustomReactionRepository _customReactions;
public ICustomReactionRepository CustomReactions => _customReactions ?? (_customReactions = new CustomReactionsRepository(_context));
private IPokeGameRepository _pokegame;
public IPokeGameRepository PokeGame => _pokegame ?? (_pokegame = new PokeGameRepository(_context));
private IWaifuRepository _waifus;
public IWaifuRepository Waifus => _waifus ?? (_waifus = new WaifuRepository(_context));
private IDiscordUserRepository _discordUsers;
public IDiscordUserRepository DiscordUsers => _discordUsers ?? (_discordUsers = new DiscordUserRepository(_context));
2017-03-30 01:51:54 +00:00
private IWarningsRepository _warnings;
public IWarningsRepository Warnings => _warnings ?? (_warnings = new WarningsRepository(_context));
2017-08-22 03:48:45 +00:00
private IXpRepository _xp;
public IXpRepository Xp => _xp ?? (_xp = new XpRepository(_context));
private IClubRepository _clubs;
public IClubRepository Clubs => _clubs ?? (_clubs = new ClubRepository(_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);
}
}
}