Skip to content

Instantly share code, notes, and snippets.

@merken
Last active January 6, 2020 13:24
Show Gist options
  • Save merken/e0c9aeffddb1e29df3cce6cd77c5d26d to your computer and use it in GitHub Desktop.
Save merken/e0c9aeffddb1e29df3cce6cd77c5d26d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Contract;
using Microsoft.EntityFrameworkCore;
using Prise.Plugin;
namespace OldSQLPlugin
{
[Plugin(PluginType = typeof(IProductsRepository))]
public class SqlProductsRepository : IProductsRepository
{
private readonly ProductsDbContext dbContext;
internal SqlProductsRepository(ProductsDbContext dbContext)
{
this.dbContext = dbContext;
}
[PluginFactory]
public static SqlProductsRepository ThisIsTheFactoryMethod(IServiceProvider serviceProvider)
{
var service = serviceProvider.GetService(typeof(ProductsDbContext));
return new SqlProductsRepository(service as ProductsDbContext);
}
public async Task<IEnumerable<Product>> All()
{
return await dbContext.Products
.AsNoTracking()
.ToListAsync();
}
public async Task<Product> Get(int productId)
{
return await dbContext.Products
.AsNoTracking()
.FirstOrDefaultAsync(p => p.Id == productId);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment