using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore;
using OliverBooth.Blog.Data;
namespace OliverBooth.Blog.Services;
///
/// Represents an implementation of .
///
internal sealed class UserService : IUserService
{
private readonly IDbContextFactory _dbContextFactory;
///
/// Initializes a new instance of the class.
///
///
/// The used to create a .
///
public UserService(IDbContextFactory dbContextFactory)
{
_dbContextFactory = dbContextFactory;
}
///
public bool TryGetUser(Guid id, [NotNullWhen(true)] out IUser? user)
{
using BlogContext context = _dbContextFactory.CreateDbContext();
user = context.Users.Find(id);
return user is not null;
}
}