mirror of
https://github.com/tribufu/tribufu-dotnet
synced 2026-05-06 06:37:28 +00:00
Add repository seeder
This commit is contained in:
parent
92a7bb3252
commit
b6c7166b8e
3 changed files with 35 additions and 1 deletions
|
|
@ -6,7 +6,12 @@ using System.Threading.Tasks;
|
|||
|
||||
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();
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@ namespace Tribufu.Database.Repositories
|
|||
_dbSet = context.Set<T>();
|
||||
}
|
||||
|
||||
public virtual void SeedDefaults()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual IList<T> GetAll()
|
||||
{
|
||||
return [.. _dbSet];
|
||||
|
|
|
|||
25
src/Tribufu.Database/Repositories/RepositorySeeder.cs
Normal file
25
src/Tribufu.Database/Repositories/RepositorySeeder.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue