mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
🚧 Core API and abstractions extending
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions
|
||||
{
|
||||
public static class RepositoryExtension
|
||||
{
|
||||
#region DbContext
|
||||
|
||||
/// <summary>
|
||||
/// Marks the entity as created.
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <param name="entity">Entity for marking as created.</param>
|
||||
public static void MarkAsCreated(this DbContext dbContext, object entity) =>
|
||||
dbContext.Entry(entity).State = EntityState.Added;
|
||||
|
||||
/// <summary>
|
||||
/// Marks the entity as deleted.
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <param name="entity">Entity for marking as deleted.</param>
|
||||
public static void MarkAsDeleted(this DbContext dbContext, object entity) =>
|
||||
dbContext.Entry(entity).State = EntityState.Deleted;
|
||||
|
||||
/// <summary>
|
||||
/// Marks the entity as modified.
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <param name="entity">Entity for marking as modified.</param>
|
||||
public static void MarkAsModified(this DbContext dbContext, object entity) =>
|
||||
dbContext.Entry(entity).State = EntityState.Modified;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Repository
|
||||
|
||||
public static TEntity Create<TEntity>(this DbSet<TEntity> repository) where TEntity : class, new()
|
||||
{
|
||||
var entity = new TEntity();
|
||||
repository.Add(entity);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions
|
||||
{
|
||||
public static class StartupExtension
|
||||
{
|
||||
public static IServiceCollection AddQueue<T>(this IServiceCollection collection)
|
||||
{
|
||||
return collection.AddSingleton<ConcurrentQueue<T>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user