Skip to content

Commit

Permalink
[r] to primary constructors
Browse files Browse the repository at this point in the history
[r] agrument null checks
  • Loading branch information
i4004 committed May 25, 2024
1 parent 8230ca0 commit ce726c3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,28 @@

namespace Simplify.Examples.Repository.Domain.Accounts;

public class UsersService : IUsersService
public class UsersService(IGenericRepository<IUser> repository) : IUsersService
{
private readonly IGenericRepository<IUser> _repository;

public UsersService(IGenericRepository<IUser> repository)
{
_repository = repository;
}

public async Task<int> CreateUserAsync(IUser user)
{
var result = await _repository.AddAsync(user);
var result = await repository.AddAsync(user);

return (int)result;
}

public IUser GetUser(string userName)
{
if (userName == null) throw new ArgumentNullException(nameof(userName));
ArgumentNullException.ThrowIfNull(userName);

return _repository.GetSingleByQuery(x => x.Name == userName);
return repository.GetSingleByQuery(x => x.Name == userName);
}

public void SetUserCity(IUser user, ICity city)
{
if (user == null)
throw new ArgumentNullException(nameof(user));
ArgumentNullException.ThrowIfNull(user);

user.City = city ?? throw new ArgumentNullException(nameof(city));

_repository.Update(user);
repository.Update(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@

namespace Simplify.Examples.Repository.Domain.Location;

public class CitiesService : ICitiesService
public class CitiesService(IGenericRepository<ICity> repository) : ICitiesService
{
private readonly IGenericRepository<ICity> _repository;

public CitiesService(IGenericRepository<ICity> repository)
{
_repository = repository;
}

public ICity GetCity(string cityName)
{
if (cityName == null) throw new ArgumentNullException(nameof(cityName));
ArgumentNullException.ThrowIfNull(cityName);

return _repository.GetSingleByQuery(x => x.CityNames.Any(n => n.Name == cityName));
return repository.GetSingleByQuery(x => x.CityNames.Any(n => n.Name == cityName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

namespace Simplify.Examples.Repository.Domain.Location;

public class TransactCitiesService : ICitiesService
public class TransactCitiesService(ICitiesService baseService, IExampleUnitOfWork unitOfWork) : ICitiesService
{
private readonly ICitiesService _baseService;
private readonly IExampleUnitOfWork _unitOfWork;

public TransactCitiesService(ICitiesService baseService, IExampleUnitOfWork unitOfWork)
{
_baseService = baseService;
_unitOfWork = unitOfWork;
}

public ICity GetCity(string cityName)
{
_unitOfWork.BeginTransaction(IsolationLevel.ReadUncommitted);
unitOfWork.BeginTransaction(IsolationLevel.ReadUncommitted);

var item = _baseService.GetCity(cityName);
var item = baseService.GetCity(cityName);

_unitOfWork.Commit();
unitOfWork.Commit();

return item;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>

<Authors>Alexander Krylkov</Authors>
Expand Down

0 comments on commit ce726c3

Please sign in to comment.