Last active
January 6, 2020 13:24
-
-
Save merken/e0c9aeffddb1e29df3cce6cd77c5d26d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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