Skip to content

Commit

Permalink
Applied the C# 12 style to the constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Klaus committed Jan 1, 2024
1 parent d1a7036 commit 8dfb694
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 29 deletions.
15 changes: 5 additions & 10 deletions Domain.Tests/TestDbBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AK.DbSample.Database;
using AK.DbSample.Database.Configuration;
using AK.DbSample.Database.Entities;
using AK.DbSample.Domain.Configuration;

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
Expand All @@ -20,21 +20,16 @@ namespace AK.DbSample.Domain.Tests;
/// Base test class with a DI container and DB connection.
/// Derive from it when need DI and DB connection
/// </summary>
public abstract class TestDbBase : TestBase, IAsyncLifetime
public abstract class TestDbBase(ITestOutputHelper output) : TestBase, IAsyncLifetime
{
protected DataContext DataContext => Container.GetRequiredService<DataContext>();
protected readonly ITestOutputHelper Output;
protected readonly ITestOutputHelper Output = output;

/// <summary>
/// Tables that shouldn't be touched on whipping out the DB
/// </summary>
private readonly Table[] _tablesToIgnore = { Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.DefaultTableName /* "__EFMigrationsHistory" */ };
private readonly Table[] _tablesToIgnore = [Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.DefaultTableName /* "__EFMigrationsHistory" */];

protected TestDbBase(ITestOutputHelper output)
{
Output = output;
}

/// <summary>
/// Configure the DI container
/// </summary>
Expand Down Expand Up @@ -83,7 +78,7 @@ public async Task InitializeAsync()
/// <summary>
/// Wipe out all data in the database
/// </summary>
protected async Task WipeOutDbAsync()
private async Task WipeOutDbAsync()
{
Respawner? respawn = null;
try
Expand Down
9 changes: 2 additions & 7 deletions Domain/Services/BaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

namespace AK.DbSample.Domain.Services;

public abstract class BaseService
public abstract class BaseService(DataContext dataContext)
{
protected readonly DataContext DataContext;

protected BaseService(DataContext dataContext)
{
DataContext = dataContext;
}
protected readonly DataContext DataContext = dataContext;
}
4 changes: 1 addition & 3 deletions Domain/Services/Client/ClientCommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public interface IClientCommandService
Task<IDomainResult> Delete(long id);
}

public class ClientCommandService: BaseService, IClientCommandService
public class ClientCommandService(DataContext dataContext) : BaseService(dataContext), IClientCommandService
{
public ClientCommandService(DataContext dataContext) : base(dataContext) {}

public async Task<(long, IDomainResult)> Create(CreateUpdateClientRequest dto)
{
var nameCheckResult = await UniqueNameCheck(null, dto.Name);
Expand Down
4 changes: 1 addition & 3 deletions Domain/Services/Client/ClientQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public interface IClientQueryService
Task<GetClientListResponse[]> GetList(GetClientListRequest filter);
}

public class ClientQueryService: BaseService, IClientQueryService
public class ClientQueryService(DataContext dataContext) : BaseService(dataContext), IClientQueryService
{
public ClientQueryService(DataContext dataContext) : base(dataContext) {}

public async Task<(GetClientByIdResponse, IDomainResult)> GetById(long clientId)
{
var client = await DataContext.Clients
Expand Down
1 change: 1 addition & 0 deletions Domain/Services/Client/DTOs/ClientQueryDtos.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ReSharper disable NotAccessedPositionalProperty.Global
namespace AK.DbSample.Domain.Services.Client.DTOs;

public record GetClientListRequest(string? Name = null);
Expand Down
1 change: 1 addition & 0 deletions Domain/Services/Invoice/DTOs/InvoiceQueryDtos.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ReSharper disable NotAccessedPositionalProperty.Global
namespace AK.DbSample.Domain.Services.Invoice.DTOs;

public record GetInvoiceListRequest(long? ClientId = null);
Expand Down
4 changes: 1 addition & 3 deletions Domain/Services/Invoice/InvoiceCommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public interface IInvoiceCommandService
Task<IDomainResult> Delete(string number);
}

public class InvoiceCommandService: BaseService, IInvoiceCommandService
public class InvoiceCommandService(DataContext dataContext) : BaseService(dataContext), IInvoiceCommandService
{
public InvoiceCommandService(DataContext dataContext) : base(dataContext) {}

public async Task<(string, IDomainResult)> Create(CreateInvoiceRequest dto)
{
var numberCheckResult = await UniqueNumberCheck(dto.Number, true);
Expand Down
4 changes: 1 addition & 3 deletions Domain/Services/Invoice/InvoiceQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public interface IInvoiceQueryService
Task<GetInvoiceListResponse[]> GetList(GetInvoiceListRequest filter);
}

public class InvoiceQueryService: BaseService, IInvoiceQueryService
public class InvoiceQueryService(DataContext dataContext) : BaseService(dataContext), IInvoiceQueryService
{
public InvoiceQueryService(DataContext dataContext) : base(dataContext) {}

public async Task<(GetInvoiceByNumberResponse, IDomainResult)> GetByNumber(string number)
{
var invoice = await DataContext.Invoices
Expand Down

0 comments on commit 8dfb694

Please sign in to comment.