You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
}
}
The text was updated successfully, but these errors were encountered:
Looking back, I think this is cleaner. I try to limit using inheritance due to the coupling created between the base and derived classes, but I think this is definitely a situation where inheritance is preferable.
I'm not sure I will go back and change this since the current code is acceptable, but I think future DataServices will simply inherit from NonQueryDataService. Thank you your input duhowise, including the code snippet example! I love code snippets.
@duhowise or instead of all these inheritance, using virtual methods on the GenericDataService and override them on the AccoundDataService would just get the job done, and remove the need for the NonQueryDataService.
danzuep
added a commit
to danzuep/SimpleTrader
that referenced
this issue
Oct 5, 2023
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:
The text was updated successfully, but these errors were encountered: