Skip to content

Commit

Permalink
Iatsuta/62 add async query (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
iatsuta authored Aug 15, 2022
1 parent e440268 commit 8afe981
Show file tree
Hide file tree
Showing 29 changed files with 195 additions and 263 deletions.

This file was deleted.

12 changes: 0 additions & 12 deletions src/Framework.Core.VisistedQueryable/QueryableExtensions.cs

This file was deleted.

42 changes: 0 additions & 42 deletions src/Framework.Core.VisistedQueryable/VisitedQueryProvider.cs

This file was deleted.

66 changes: 0 additions & 66 deletions src/Framework.Core.VisistedQueryable/VisitedQueryable.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public TryProcessDbSessionMiddleware(RequestDelegate next)
this.next = next;
}

public Task Invoke(HttpContext context, IWebApiDBSessionModeResolver sessionModeResolver)
public async Task Invoke(HttpContext context, IWebApiDBSessionModeResolver sessionModeResolver)
{
try
{
Expand All @@ -38,7 +38,7 @@ public Task Invoke(HttpContext context, IWebApiDBSessionModeResolver sessionMode
}
}

return this.next(context);
await this.next(context);
}
catch
{
Expand All @@ -47,7 +47,7 @@ public Task Invoke(HttpContext context, IWebApiDBSessionModeResolver sessionMode
}
finally
{
context.RequestServices.TryCloseDbSession();
await context.RequestServices.TryCloseDbSessionAsync(context.RequestAborted);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public WebApiExceptionExpanderMiddleware(RequestDelegate next)
this.next = next;
}

public Task Invoke(HttpContext context, IWebApiExceptionExpander exceptionExpander)
public async Task Invoke(HttpContext context, IWebApiExceptionExpander exceptionExpander)
{
try
{
return this.next(context);
await this.next(context);
}
catch (Exception ex)
{
Expand Down
22 changes: 0 additions & 22 deletions src/IAD.Framework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GeneratedTools", "Generated
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Framework.Authorization.ApproveWorkflow", "_Authorization\Framework.Authorization.ApproveWorkflow\Framework.Authorization.ApproveWorkflow.csproj", "{24F41E7D-4D0F-4B52-8A35-18C4F6FBD31F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Framework.Core.VisistedQueryable", "Framework.Core.VisistedQueryable\Framework.Core.VisistedQueryable.csproj", "{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -3522,26 +3520,6 @@ Global
{24F41E7D-4D0F-4B52-8A35-18C4F6FBD31F}.Release|x64.Build.0 = Release|Any CPU
{24F41E7D-4D0F-4B52-8A35-18C4F6FBD31F}.Release|x86.ActiveCfg = Release|Any CPU
{24F41E7D-4D0F-4B52-8A35-18C4F6FBD31F}.Release|x86.Build.0 = Release|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Debug|ARM.ActiveCfg = Debug|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Debug|ARM.Build.0 = Debug|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Debug|x64.ActiveCfg = Debug|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Debug|x64.Build.0 = Debug|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Debug|x86.ActiveCfg = Debug|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Debug|x86.Build.0 = Debug|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Release|Any CPU.Build.0 = Release|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Release|ARM.ActiveCfg = Release|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Release|ARM.Build.0 = Release|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Release|x64.ActiveCfg = Release|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Release|x64.Build.0 = Release|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Release|x86.ActiveCfg = Release|Any CPU
{FC4C1FC4-BCDA-40E6-BC57-F9F804B0028E}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Framework.DomainDriven;
using Framework.DomainDriven.BLL;
using Framework.Exceptions;
using Framework.HierarchicalExpand;
using Framework.Persistent;

namespace Framework.Authorization.BLL
Expand Down
6 changes: 4 additions & 2 deletions src/_DomainDriven/Framework.DomainDriven.Core/BLL/BLLBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;

using Framework.Core;
using Framework.DomainDriven.DAL.Revisions;
Expand Down Expand Up @@ -265,7 +267,7 @@ public OData.SelectOperationResult<TDomainObject> GetObjectsByOData(OData.Select
/// <returns></returns>
public IQueryable<TDomainObject> GetUnsecureQueryable(IFetchContainer<TDomainObject> fetchContainer, LockRole lockRole = LockRole.None)
{
return this._dal.GetQueryable(lockRole, fetchContainer).Visit(this.GetQueryableExpressionVisitor());
return this._dal.GetQueryable(lockRole, fetchContainer, this.GetQueryableExpressionVisitor());
}

public IQueryable<TDomainObject> GetUnsecureQueryable(
Expand Down Expand Up @@ -444,7 +446,7 @@ public TDomainObject GetObjectBy(Expression<Func<TDomainObject, bool>> filter, b
return this.GetObjectBy(filter, throwOnNotFound, fetchs.ToFetchContainer());
}

public virtual List<TDomainObject> GetFullList(IFetchContainer<TDomainObject> fetchContainer = null)
public List<TDomainObject> GetFullList(IFetchContainer<TDomainObject> fetchContainer = null)
{
return this.GetSecureQueryable(fetchContainer).ToList();
}
Expand Down
2 changes: 2 additions & 0 deletions src/_DomainDriven/Framework.DomainDriven.Core/BLL/IBLLBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;

using Framework.Core;
using Framework.Exceptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IOperationBLLBase<in TDomainObject>
{
void Save([NotNull] TDomainObject domainObject);


void Remove([NotNull] TDomainObject domainObject);
}

Expand Down
3 changes: 2 additions & 1 deletion src/_DomainDriven/Framework.DomainDriven.Core/DAL/IDAL.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Linq.Expressions;

using Framework.DomainDriven.DAL.Revisions;

Expand All @@ -10,7 +11,7 @@ public interface IDAL<TDomainObject, TIdent> : IAuditDAL<TDomainObject, TIdent>
/// Предоставляет Queryable в контексте Read
/// </summary>
/// <returns></returns>
IQueryable<TDomainObject> GetQueryable(LockRole lockRole, IFetchContainer<TDomainObject> fetchContainer = null);
IQueryable<TDomainObject> GetQueryable(LockRole lockRole, IFetchContainer<TDomainObject> fetchContainer = null, ExpressionVisitor visitor = null);

TDomainObject GetById(TIdent id, LockRole lockRole);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<Compile Include="..\..\__SolutionItems\CommonAssemblyInfo.cs" Link="Properties\CommonAssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Framework.Core.VisistedQueryable\Framework.Core.VisistedQueryable.csproj" />
<ProjectReference Include="..\..\Framework.HierarchicalExpand\Framework.HierarchicalExpand.csproj" />
<ProjectReference Include="..\..\Framework.OData\Framework.OData.csproj" />
<ProjectReference Include="..\..\Framework.Persistent.Mapping\Framework.Persistent.Mapping.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using Framework.DomainDriven.BLL.Tracking;
using Framework.Persistent;

namespace Framework.DomainDriven
{
public interface IDBSession : ICurrentRevisionService, IDisposable
public interface IDBSession : ICurrentRevisionService, IAsyncDisposable, IDisposable
{
DBSessionMode SessionMode { get; }

Expand All @@ -18,7 +20,12 @@ IDALFactory<TPersistentDomainObjectBase, TIdent> GetDALFactory<TPersistentDomain
/// <summary>
/// Мануальный флаш сессии, при его вызове срабатывают только Flushed-евенты, TransactionCompleted-евенты вызываются только при закрытие сессии
/// </summary>
void Flush();
void Flush()
{
this.FlushAsync().GetAwaiter().GetResult();
}

Task FlushAsync(CancellationToken cancellationToken = default);

IEnumerable<ObjectModification> GetModifiedObjectsFromLogic();

Expand All @@ -45,6 +52,16 @@ IDALFactory<TPersistentDomainObjectBase, TIdent> GetDALFactory<TPersistentDomain
/// </summary>
void AsWritable();

void Close();
public void Close()
{
this.CloseAsync().GetAwaiter().GetResult();
}

Task CloseAsync(CancellationToken cancellationToken = default);

void IDisposable.Dispose()
{
this.DisposeAsync().GetAwaiter().GetResult();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using JetBrains.Annotations;

Expand All @@ -13,15 +15,15 @@ public static class ServiceProviderExtensions
/// </summary>
/// <param name="serviceProvider"></param>
/// <exception cref="ArgumentNullException"></exception>
public static void TryCloseDbSession([NotNull] this IServiceProvider serviceProvider)
public static async Task TryCloseDbSessionAsync([NotNull] this IServiceProvider serviceProvider, CancellationToken cancellationToken = default)
{
if (serviceProvider == null) throw new ArgumentNullException(nameof(serviceProvider));

var lazyDbSession = serviceProvider.GetRequiredService<Lazy<IDBSession>>();

if (lazyDbSession.IsValueCreated)
{
lazyDbSession.Value.Close();
await lazyDbSession.Value.CloseAsync(cancellationToken);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ public virtual void Remove(TDomainObject domainObject)
this.session.RegisterModified(domainObject, ModificationType.Remove);

this.InnerSession.Delete(domainObject);

// this.InnerSession.Delete(this.InnerSession.Get<TDomainObject>(domainObject.Id));
}

public IQueryable<TDomainObject> GetQueryable(LockRole lockRole, IFetchContainer<TDomainObject> fetchContainer)
public IQueryable<TDomainObject> GetQueryable(LockRole lockRole, IFetchContainer<TDomainObject> fetchContainer, ExpressionVisitor visitor = null)
{
var queryable = this.InnerSession.Query<TDomainObject>();

(queryable.Provider as VisitedQueryProvider)
.FromMaybe("Register VisitedQueryProvider in Nhib configuration")
.Visitor = visitor;

var fetchsResult = queryable.WithFetchs(fetchContainer);

if (lockRole == LockRole.None)
Expand Down
Loading

0 comments on commit 8afe981

Please sign in to comment.