mirror of
https://github.com/tribufu/tribufu-dotnet
synced 2026-02-04 02:36:55 +00:00
Add repository seeder
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user