using Microsoft.EntityFrameworkCore; using OliverBooth.Data; using OliverBooth.Data.Blog; namespace OliverBooth.Services; public sealed class BlogService { private IDbContextFactory _dbContextFactory; /// /// Initializes a new instance of the class. /// /// The . public BlogService(IDbContextFactory dbContextFactory) { _dbContextFactory = dbContextFactory; } /// /// Gets a read-only view of all blog posts. /// /// A read-only view of all blog posts. public IReadOnlyCollection AllPosts { get { using BlogContext context = _dbContextFactory.CreateDbContext(); return context.BlogPosts.OrderByDescending(p => p.Published).ToArray(); } } }