This file contains hidden or 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
| [Route("api/[controller]")] | |
| [ApiController] | |
| public class BooksController : ControllerBase | |
| { | |
| private IUnitOfWork _unitOfWork; | |
| public BooksController(IUnitOfWork unitOfWork) | |
| { | |
| _unitOfWork = unitOfWork; | |
| } |
This file contains hidden or 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
| public class UnitOfWork :IUnitOfWork | |
| { | |
| private readonly BookStoreDbContext _context; | |
| public IBooksRepository Books { get; } | |
| public ICatalogueRepository Catalogues { get; } | |
| public UnitOfWork(BookStoreDbContext bookStoreDbContext, | |
| IBooksRepository booksRepository, | |
| ICatalogueRepository catalogueRepository) |
This file contains hidden or 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
| public class BooksRepository:GenericRepository<Book>, IBooksRepository | |
| { | |
| public BooksRepository(BookStoreDbContext context) : base(context) | |
| { | |
| } | |
| public IEnumerable<Book> GetBooksByGenre(string Genre) | |
| { | |
| return _context.Books.Where(x => x.Genre == Genre); |
This file contains hidden or 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
| public abstract class GenericRepository<T> : IGenericRepository<T> where T : class | |
| { | |
| protected readonly BookStoreDbContext _context; | |
| public GenericRepository(BookStoreDbContext context) | |
| { | |
| _context = context; | |
| } | |
| public async Task<T> Get(int id) | |
| { |
This file contains hidden or 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
| public interface IUnitOfWork : IDisposable | |
| { | |
| IBooksRepository Books { get; } | |
| ICatalogueRepository Catalogues { get; } | |
| int Complete(); | |
| } |
This file contains hidden or 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.Collections.Generic; | |
| using System.Threading.Tasks; | |
| using BookStore.Domain.CatalogueAggregate; | |
| using Microsoft.EntityFrameworkCore; | |
| namespace BookStore.Repository | |
| { | |
| class CatalogueRepository : ICatalogueRepository | |
| { | |
| private readonly BookStoreDbContext _context; |
This file contains hidden or 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
| public void ConfigureServices(IServiceCollection services) | |
| { | |
| services.AddRepository(); | |
| services.AddControllers(); | |
| } |
This file contains hidden or 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 BookStore.Domain.BooksAggregate; | |
| using Microsoft.EntityFrameworkCore; | |
| using Microsoft.Extensions.DependencyInjection; | |
| namespace BookStore.Repository | |
| { | |
| public static class DependencyInjection | |
| { | |
| public static IServiceCollection AddRepository(this IServiceCollection services) | |
| { |
This file contains hidden or 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
| public class BookStoreDbContext : DbContext | |
| { | |
| public BookStoreDbContext(DbContextOptions<BookStoreDbContext> options) : base(options) | |
| { } | |
| public DbSet<Book> BookItems { get; set; } | |
| } |
This file contains hidden or 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
| public interface IBooksRepository:IGenericRepository<Book> | |
| { | |
| } |