Skip to content

Commit

Permalink
Merge pull request #69 from neozhu/dev
Browse files Browse the repository at this point in the history
clean code add global using in application project
  • Loading branch information
neozhu authored Nov 11, 2021
2 parents 9883b9f + 4f41cd8 commit dfb6fe9
Show file tree
Hide file tree
Showing 95 changed files with 351 additions and 613 deletions.
489 changes: 301 additions & 188 deletions .editorconfig

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/Application/Common/Behaviours/AuthorizationBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Exceptions;
using CleanArchitecture.Razor.Application.Common.Interfaces;
using CleanArchitecture.Razor.Application.Common.Interfaces.Identity;
using CleanArchitecture.Razor.Application.Common.Security;
using MediatR;
using System.Reflection;

namespace CleanArchitecture.Razor.Application.Common.Behaviours;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Interfaces.Caching;
using LazyCache;
using MediatR;
using Microsoft.Extensions.Logging;

namespace CleanArchitecture.Razor.Application.Common.Behaviours;
Expand Down
2 changes: 0 additions & 2 deletions src/Application/Common/Behaviours/CachingBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Interfaces.Caching;
using LazyCache;
using MediatR;
using Microsoft.Extensions.Logging;

namespace CleanArchitecture.Razor.Application.Common.Behaviours;
Expand Down
1 change: 0 additions & 1 deletion src/Application/Common/Behaviours/LoggingBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Interfaces;
using CleanArchitecture.Razor.Application.Common.Interfaces.Identity;
using MediatR.Pipeline;
using Microsoft.Extensions.Logging;
Expand Down
2 changes: 0 additions & 2 deletions src/Application/Common/Behaviours/PerformanceBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Interfaces;
using CleanArchitecture.Razor.Application.Common.Interfaces.Identity;
using MediatR;
using Microsoft.Extensions.Logging;
using System.Diagnostics;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using MediatR;
using Microsoft.Extensions.Logging;

namespace CleanArchitecture.Razor.Application.Common.Behaviours;
Expand Down
2 changes: 0 additions & 2 deletions src/Application/Common/Behaviours/ValidationBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using FluentValidation;
using MediatR;
using ValidationException = CleanArchitecture.Razor.Application.Common.Exceptions.ValidationException;

namespace CleanArchitecture.Razor.Application.Common.Behaviours;
Expand Down
1 change: 0 additions & 1 deletion src/Application/Common/Extensions/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.ComponentModel;
using System.Globalization;
using System.Reflection;
using CleanArchitecture.Razor.Application.Common.Models;

namespace CleanArchitecture.Razor.Application.Common.Extensions;

Expand Down
2 changes: 0 additions & 2 deletions src/Application/Common/Extensions/QueryableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Interfaces;
using CleanArchitecture.Razor.Domain.Common;
using Microsoft.EntityFrameworkCore;

namespace CleanArchitecture.Razor.Application.Common.Extensions;

Expand Down
2 changes: 0 additions & 2 deletions src/Application/Common/Interfaces/IApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Domain.Entities;
using CleanArchitecture.Razor.Domain.Entities.Audit;
using CleanArchitecture.Razor.Domain.Entities.Log;
using CleanArchitecture.Razor.Domain.Entities.Worflow;
using Microsoft.EntityFrameworkCore;

namespace CleanArchitecture.Razor.Application.Common.Interfaces;

Expand Down
2 changes: 0 additions & 2 deletions src/Application/Common/Interfaces/IUploadService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Models;

namespace CleanArchitecture.Razor.Application.Common.Interfaces;

public interface IUploadService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Interfaces.Identity.DTOs;
using CleanArchitecture.Razor.Application.Common.Models;

namespace CleanArchitecture.Razor.Application.Common.Interfaces.Identity;

Expand Down
2 changes: 0 additions & 2 deletions src/Application/Common/Mappings/IMapFrom.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using AutoMapper;

namespace CleanArchitecture.Razor.Application.Common.Mappings;

public interface IMapFrom<T>
Expand Down
6 changes: 0 additions & 6 deletions src/Application/Common/Mappings/MappingExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using AutoMapper;
using AutoMapper.QueryableExtensions;
using CleanArchitecture.Razor.Application.Common.Models;
using CleanArchitecture.Razor.Application.Models;
using Microsoft.EntityFrameworkCore;

namespace CleanArchitecture.Razor.Application.Common.Mappings;

public static class MappingExtensions
Expand Down
1 change: 0 additions & 1 deletion src/Application/Common/Mappings/MappingProfile.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using AutoMapper;
using System.Reflection;

namespace CleanArchitecture.Razor.Application.Common.Mappings;
Expand Down
1 change: 0 additions & 1 deletion src/Application/Common/Models/DomainEventNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Domain.Common;
using MediatR;

namespace CleanArchitecture.Razor.Application.Common.Models;

Expand Down
4 changes: 1 addition & 3 deletions src/Application/Common/Models/PaginatedData.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore;

namespace CleanArchitecture.Razor.Application.Models;
namespace CleanArchitecture.Razor.Application.Common.Models;

public class PaginatedData<T>
{
Expand Down
2 changes: 0 additions & 2 deletions src/Application/Common/Models/PaginatedList.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore;

namespace CleanArchitecture.Razor.Application.Common.Models;

public class PaginatedList<T>
Expand Down
2 changes: 0 additions & 2 deletions src/Application/Common/Models/Result.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Interfaces;

namespace CleanArchitecture.Razor.Application.Common.Models;

public class Result : IResult
Expand Down
2 changes: 0 additions & 2 deletions src/Application/Common/Specification/Specification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Linq.Expressions;
using CleanArchitecture.Razor.Application.Common.Extensions;
using CleanArchitecture.Razor.Application.Common.Interfaces;
using CleanArchitecture.Razor.Domain.Common;

namespace CleanArchitecture.Razor.Application.Common.Specification;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,51 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using AutoMapper;
using CleanArchitecture.Razor.Application.Common.Interfaces;
using CleanArchitecture.Razor.Application.Common.Interfaces.Caching;
using CleanArchitecture.Razor.Application.Common.Mappings;
using CleanArchitecture.Razor.Application.Common.Models;
using CleanArchitecture.Razor.Application.Customers.Caching;
using CleanArchitecture.Razor.Application.Customers.DTOs;
using CleanArchitecture.Razor.Domain.Entities;
using CleanArchitecture.Razor.Domain.Events;
using MediatR;

namespace CleanArchitecture.Razor.Application.Customers.Commands.AddEdit
namespace CleanArchitecture.Razor.Application.Customers.Commands.AddEdit;

public class AddEditCustomerCommand : CustomerDto, IRequest<Result<int>>, IMapFrom<Customer>, ICacheInvalidator
{
public class AddEditCustomerCommand : CustomerDto, IRequest<Result<int>>, IMapFrom<Customer>, ICacheInvalidator
{
public string CacheKey => CustomerCacheKey.GetAllCacheKey;
public string CacheKey => CustomerCacheKey.GetAllCacheKey;

public CancellationTokenSource ResetCacheToken => CustomerCacheTokenSource.ResetCacheToken;
}
public CancellationTokenSource ResetCacheToken => CustomerCacheTokenSource.ResetCacheToken;
}

public class AddEditCustomerCommandHandler : IRequestHandler<AddEditCustomerCommand, Result<int>>
{
private readonly IApplicationDbContext _context;
private readonly IMapper _mapper;

public class AddEditCustomerCommandHandler : IRequestHandler<AddEditCustomerCommand, Result<int>>
public AddEditCustomerCommandHandler(
IApplicationDbContext context,
IMapper mapper
)
{
_context = context;
_mapper = mapper;
}
public async Task<Result<int>> Handle(AddEditCustomerCommand request, CancellationToken cancellationToken)
{
private readonly IApplicationDbContext _context;
private readonly IMapper _mapper;

public AddEditCustomerCommandHandler(
IApplicationDbContext context,
IMapper mapper
)
if (request.Id > 0)
{
_context = context;
_mapper = mapper;
var customer = await _context.Customers.FindAsync(new object[] { request.Id }, cancellationToken);
customer = _mapper.Map(request, customer);
await _context.SaveChangesAsync(cancellationToken);
return Result<int>.Success(customer.Id);
}
public async Task<Result<int>> Handle(AddEditCustomerCommand request, CancellationToken cancellationToken)
else
{

if (request.Id > 0)
{
var customer = await _context.Customers.FindAsync(new object[] { request.Id }, cancellationToken);
customer=_mapper.Map(request, customer);
await _context.SaveChangesAsync(cancellationToken);
return Result<int>.Success(customer.Id);
}
else
{
var customer = _mapper.Map<Customer>(request);
var createevent = new CustomerCreatedEvent(customer);
customer.DomainEvents.Add(createevent);
_context.Customers.Add(customer);
await _context.SaveChangesAsync(cancellationToken);
return Result<int>.Success(customer.Id);
}


var customer = _mapper.Map<Customer>(request);
var createevent = new CustomerCreatedEvent(customer);
customer.DomainEvents.Add(createevent);
_context.Customers.Add(customer);
await _context.SaveChangesAsync(cancellationToken);
return Result<int>.Success(customer.Id);
}


}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using FluentValidation;

namespace CleanArchitecture.Razor.Application.Customers.Commands.AddEdit
{
public class AddEditCustomerCommandValidator : AbstractValidator<AddEditCustomerCommand>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Interfaces;
using CleanArchitecture.Razor.Application.Common.Interfaces.Caching;
using CleanArchitecture.Razor.Application.Common.Models;
using CleanArchitecture.Razor.Application.Customers.Caching;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace CleanArchitecture.Razor.Application.Customers.Commands.Delete
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using FluentValidation;

namespace CleanArchitecture.Razor.Application.Customers.Commands.Delete
{
public class DeleteCustomerCommandValidator : AbstractValidator<DeleteCustomerCommand>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Data;
using AutoMapper;
using CleanArchitecture.Razor.Application.Common.Interfaces;
using CleanArchitecture.Razor.Application.Common.Interfaces.Caching;
using CleanArchitecture.Razor.Application.Common.Models;
using CleanArchitecture.Razor.Application.Customers.Caching;
using CleanArchitecture.Razor.Application.Customers.Commands.AddEdit;
using CleanArchitecture.Razor.Application.Customers.DTOs;
using CleanArchitecture.Razor.Domain.Entities;
using FluentValidation;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;

namespace CleanArchitecture.Razor.Application.Customers.Commands.Import
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using FluentValidation;

namespace CleanArchitecture.Razor.Application.Customers.Commands.Import
{
public class ImportCustomersCommandValidator : AbstractValidator<ImportCustomersCommand>
Expand Down
3 changes: 0 additions & 3 deletions src/Application/Customers/DTOs/CustomerDto.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Mappings;
using CleanArchitecture.Razor.Domain.Entities;

namespace CleanArchitecture.Razor.Application.Customers.DTOs
{
public partial class CustomerDto:IMapFrom<Customer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Razor.Application.Common.Models;
using CleanArchitecture.Razor.Domain.Events;
using MediatR;
using Microsoft.Extensions.Logging;

namespace CleanArchitecture.Razor.Application.Customers.EventHandlers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using AutoMapper;
using CleanArchitecture.Razor.Application.Common.Extensions;
using CleanArchitecture.Razor.Application.Common.Interfaces;
using CleanArchitecture.Razor.Application.Models;
using CleanArchitecture.Razor.Domain.Entities;
using System.Linq.Dynamic.Core;
using MediatR;
using CleanArchitecture.Razor.Application.Common.Mappings;
using AutoMapper.QueryableExtensions;
using CleanArchitecture.Razor.Application.Customers.DTOs;
using CleanArchitecture.Razor.Application.Common.Specification;
using CleanArchitecture.Razor.Application.Common.Interfaces.Caching;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Primitives;
using CleanArchitecture.Razor.Application.Customers.Caching;
using CleanArchitecture.Razor.Application.Common.Models;

namespace CleanArchitecture.Razor.Application.Customers.Queries.PaginationQuery
{
Expand Down
Loading

0 comments on commit dfb6fe9

Please sign in to comment.