Skip to content

Reduce Code duplication in AccountDataService even further #6

@duhowise

Description

@duhowise

AccountDataService could inherit from NonQueryDataService thereby removing the need to write out or have to explicitly delegate functionality to NonQueryDataService... here's what I mean:

public class AccountDataService : NonQueryDataService<Account>, IDataService<Account>
{
    private readonly SimpleTraderDbContextFactory _contextFactory;

    public AccountDataService(SimpleTraderDbContextFactory contextFactory) : base(contextFactory)
    {
        _contextFactory = contextFactory;
    }

    public async Task<IEnumerable<Account>> GetAll()
    {
        await using var context = _contextFactory.CreateDbContext(new[] {""});
        var list = await context.Accounts.Include(x => x.AssetTransactions).Include(x => x.AccountHolder)
            .ToListAsync();
        return list;
    }

    public async Task<Account> Get(int id)
    {
        await using var context = _contextFactory.CreateDbContext(new[] {""});
        var entity = await context.Accounts.Include(x => x.AssetTransactions).Include(x => x.AccountHolder)
            .FirstOrDefaultAsync(x => x.Id == id);
        return entity;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions