Add link stuff #8
@ -1,4 +1,3 @@
|
||||
using System.Threading.Tasks;
|
||||
using HN.Domain;
|
||||
using HN.Infrastructure;
|
||||
using MediatR;
|
||||
@ -11,14 +10,6 @@ using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Website
|
||||
{
|
||||
public class LinkRepository : ILinkRepository
|
||||
{
|
||||
public Task AddAsync(Link link)
|
||||
{
|
||||
throw new System.NotImplementedException("link repository not implemented yet");
|
||||
}
|
||||
}
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
@ -32,9 +23,9 @@ namespace Website
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddDbContext<HNDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("Default")));
|
||||
services.AddSingleton<ILinkRepository, LinkRepository>();
|
||||
services.AddControllersWithViews();
|
||||
services.AddScoped<ILinkRepository, LinkRepository>();
|
||||
services.AddMediatR(typeof(HN.Application.AddLinkCommand));
|
||||
services.AddControllersWithViews();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
||||
17
Infrastructure/LinkRepository.cs
Normal file
17
Infrastructure/LinkRepository.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Threading.Tasks;
|
||||
using HN.Domain;
|
||||
|
||||
namespace HN.Infrastructure
|
||||
{
|
||||
public sealed class LinkRepository : Repository<Link>, ILinkRepository
|
||||
{
|
||||
public LinkRepository(HNDbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task AddAsync(Link link)
|
||||
{
|
||||
await base.AddAsync(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Infrastructure/Repository.cs
Normal file
24
Infrastructure/Repository.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HN.Infrastructure
|
||||
{
|
||||
public abstract class Repository<TEntity> where TEntity : class
|
||||
{
|
||||
private readonly HNDbContext _context;
|
||||
|
||||
protected readonly DbSet<TEntity> Entries;
|
||||
|
||||
protected Repository(HNDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
Entries = _context.Set<TEntity>();
|
||||
}
|
||||
|
||||
protected async Task AddAsync(params TEntity[] entities)
|
||||
{
|
||||
await Entries.AddRangeAsync(entities);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user