Skip to content

Commit

Permalink
更新AOP配置扩展方法
Browse files Browse the repository at this point in the history
  • Loading branch information
UtilCore committed Nov 5, 2023
1 parent 4877edf commit 7d5f37a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build/version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<VersionMajor>7</VersionMajor>
<VersionMinor>1</VersionMinor>
<VersionPatch>67</VersionPatch>
<VersionPatch>68</VersionPatch>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
Expand Down
16 changes: 11 additions & 5 deletions src/Util.Aop.AspectCore/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Util.Configs;
using Util.Helpers;

namespace Util.Aop;

Expand All @@ -24,13 +23,22 @@ public static IAppBuilder AddAop( this IAppBuilder builder,bool isEnableIAopProx
return builder.AddAop( null, isEnableIAopProxy );
}

/// <summary>
/// 启用AspectCore拦截器
/// </summary>
/// <param name="builder">应用生成器</param>
/// <param name="setupAction">AspectCore拦截器配置操作</param>
public static IAppBuilder AddAop( this IAppBuilder builder, Action<IAspectConfiguration> setupAction ) {
return builder.AddAop( setupAction, false );
}

/// <summary>
/// 启用AspectCore拦截器
/// </summary>
/// <param name="builder">应用生成器</param>
/// <param name="setupAction">AspectCore拦截器配置操作</param>
/// <param name="isEnableIAopProxy">是否启用IAopProxy接口标记</param>
public static IAppBuilder AddAop( this IAppBuilder builder, Action<IAspectConfiguration> setupAction, bool isEnableIAopProxy ) {
private static IAppBuilder AddAop( this IAppBuilder builder, Action<IAspectConfiguration> setupAction, bool isEnableIAopProxy ) {
builder.CheckNull( nameof( builder ) );
builder.Host.UseServiceProviderFactory( new DynamicProxyServiceProviderFactory() );
builder.Host.ConfigureServices( ( context, services ) => {
Expand Down Expand Up @@ -61,8 +69,6 @@ private static bool IsProxy( Type type, bool isEnableIAopProxy ) {
if ( type == null )
return false;
if ( isEnableIAopProxy == false ) {
if ( Reflection.GetTopBaseType( type ).SafeString() == "Microsoft.EntityFrameworkCore.DbContext" )
return false;
if ( type.SafeString().Contains( "Xunit.DependencyInjection.ITestOutputHelperAccessor" ) )
return false;
return true;
Expand All @@ -78,7 +84,7 @@ private static bool IsProxy( Type type, bool isEnableIAopProxy ) {
}

/// <summary>
/// 注册拦截作用域
/// 注册拦截器服务
/// </summary>
private static void RegisterAspectScoped( IServiceCollection services ) {
services.AddScoped<IAspectScheduler, ScopeAspectScheduler>();
Expand Down
4 changes: 4 additions & 0 deletions src/Util.Application.EntityFrameworkCore/CrudServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ protected CrudServiceBase( IServiceProvider serviceProvider, IUnitOfWork unitOfW

/// <inheritdoc />
public virtual async Task<string> CreateAsync( TCreateRequest request ) {
request.CheckNull( nameof(request) );
request.Validate();
var entity = ToEntity( request );
entity.CheckNull( nameof( entity ) );
await CreateAsync( entity );
Expand Down Expand Up @@ -199,6 +201,8 @@ protected virtual Task CreateCommitAfterAsync( TEntity entity ) {

/// <inheritdoc />
public virtual async Task UpdateAsync( TUpdateRequest request ) {
request.CheckNull( nameof(request) );
request.Validate();
if ( request.Id.IsEmpty() )
throw new InvalidOperationException( R.IdIsEmpty );
var oldEntity = await FindOldEntityAsync( request.Id );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ protected TreeServiceBase( IServiceProvider serviceProvider, IUnitOfWork unitOfW
/// </summary>
/// <param name="request">创建参数</param>
public virtual async Task<string> CreateAsync( TCreateRequest request ) {
request.CheckNull( nameof( request ) );
request.Validate();
var entity = ToEntity( request );
entity.CheckNull( nameof( entity ) );
await CreateAsync( entity );
Expand Down Expand Up @@ -177,6 +179,8 @@ protected virtual Task CreateCommitAfterAsync( TEntity entity ) {

/// <inheritdoc />
public virtual async Task UpdateAsync( TUpdateRequest request ) {
request.CheckNull( nameof( request ) );
request.Validate();
if ( request.Id.IsEmpty() )
throw new InvalidOperationException( R.IdIsEmpty );
var oldEntity = await FindOldEntityAsync( request.Id );
Expand Down
8 changes: 3 additions & 5 deletions src/Util.Application/ICrudService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Util.Aop;
using Util.Applications.Dtos;
using Util.Applications.Dtos;
using Util.Data.Queries;
using Util.Validation;

namespace Util.Applications;

Expand Down Expand Up @@ -31,12 +29,12 @@ public interface ICrudService<TDto, in TCreateRequest, in TUpdateRequest, in TQu
/// 创建
/// </summary>
/// <param name="request">创建参数</param>
Task<string> CreateAsync( [NotNull] [Valid] TCreateRequest request );
Task<string> CreateAsync( TCreateRequest request );
/// <summary>
/// 修改
/// </summary>
/// <param name="request">修改参数</param>
Task UpdateAsync( [NotNull] [Valid] TUpdateRequest request );
Task UpdateAsync( TUpdateRequest request );
/// <summary>
/// 删除
/// </summary>
Expand Down
8 changes: 3 additions & 5 deletions src/Util.Application/Trees/ITreeService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Util.Aop;
using Util.Applications.Dtos;
using Util.Applications.Dtos;
using Util.Data.Trees;
using Util.Validation;

namespace Util.Applications.Trees;

Expand Down Expand Up @@ -31,12 +29,12 @@ public interface ITreeService<TDto, in TCreateRequest, in TUpdateRequest, in TQu
/// 创建
/// </summary>
/// <param name="request">创建参数</param>
Task<string> CreateAsync( [NotNull][Valid] TCreateRequest request );
Task<string> CreateAsync( TCreateRequest request );
/// <summary>
/// 修改
/// </summary>
/// <param name="request">修改参数</param>
Task UpdateAsync( [NotNull][Valid] TUpdateRequest request );
Task UpdateAsync( TUpdateRequest request );
/// <summary>
/// 删除
/// </summary>
Expand Down

0 comments on commit 7d5f37a

Please sign in to comment.