Add repository seeder

This commit is contained in:
2025-12-05 10:17:08 -03:00
parent 92a7bb3252
commit b6c7166b8e
3 changed files with 35 additions and 1 deletions

View File

@@ -6,7 +6,12 @@ using System.Threading.Tasks;
namespace Tribufu.Database.Repositories namespace Tribufu.Database.Repositories
{ {
public interface IRepository<T, K> where T : class public interface IRepository
{
void SeedDefaults();
}
public interface IRepository<T, K> : IRepository where T : class
{ {
IList<T> GetAll(); IList<T> GetAll();

View File

@@ -21,6 +21,10 @@ namespace Tribufu.Database.Repositories
_dbSet = context.Set<T>(); _dbSet = context.Set<T>();
} }
public virtual void SeedDefaults()
{
}
public virtual IList<T> GetAll() public virtual IList<T> GetAll()
{ {
return [.. _dbSet]; return [.. _dbSet];

View File

@@ -0,0 +1,25 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using System.Collections.Generic;
namespace Tribufu.Database.Repositories
{
public class RepositorySeeder
{
private readonly IEnumerable<IRepository> _repositories;
public RepositorySeeder(IEnumerable<IRepository> repositories)
{
_repositories = repositories;
}
public void Run()
{
foreach (var repo in _repositories)
{
repo.SeedDefaults();
}
}
}
}