Skip to content

Commit

Permalink
add support for SetDefaultLogicOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Feb 2, 2024
1 parent 6ab1e11 commit 730e43d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.47</Version>
<Version>0.0.1.48</Version>
<Description>asp core servces.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,services,asp,aspnet</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.47</Version>
<Version>0.0.1.48</Version>
<Description>asp core servces.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,services,asp,aspnet,aspcore,efcore</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ public virtual IDatabase GetDatabase<TContext>()
}

#region ContractLogic
LogicOptions? _defaultLogicOptions;
/// <summary>
///
/// </summary>
public virtual void SetDefaultLogicOptions(LogicOptions logicOptions)
{
_defaultLogicOptions = logicOptions;
}

LogicOptions GetLogicOptions(LogicOptions logicOptions)
{
if (_defaultLogicOptions.HasValue && logicOptions.UniqueIdentityStrategy == DataTypes.UniqueIdentityStrategy.Default)
return _defaultLogicOptions.Value;
return logicOptions;
}

/// <summary>
///
/// </summary>
Expand All @@ -117,7 +133,7 @@ public virtual IDatabase GetDatabase<TContext>()
public virtual IContractLogic<TEntity, TEntity, TEntity, TEntity, long> GetLongLogic<TEntity>(LogicOptions logicOptions = default)
where TEntity : class
{
return GetInternalLongContractLogic<TEntity, TEntity, TEntity, TEntity>(logicOptions);
return GetInternalLongContractLogic<TEntity, TEntity, TEntity, TEntity>(GetLogicOptions(logicOptions));
}

/// <summary>
Expand All @@ -128,7 +144,7 @@ public virtual IContractLogic<TEntity, TEntity, TEntity, TEntity, long> GetLongL
/// <exception cref="NotImplementedException"></exception>
public IContractLogic<TEntity, TEntity, TEntity, TEntity, TEntity> GetLogic<TEntity>(LogicOptions logicOptions = default) where TEntity : class
{
return GetInternalContractLogic<TEntity, TEntity, TEntity, TEntity, TEntity>(logicOptions);
return GetInternalContractLogic<TEntity, TEntity, TEntity, TEntity, TEntity>(GetLogicOptions(logicOptions));
}

/// <summary>
Expand All @@ -141,7 +157,7 @@ public virtual IContractLogic<TEntity, TContract, TContract, TContract, long> Ge
where TContract : class
where TEntity : class
{
return GetInternalLongContractLogic<TEntity, TContract, TContract, TContract>(logicOptions);
return GetInternalLongContractLogic<TEntity, TContract, TContract, TContract>(GetLogicOptions(logicOptions));
}

/// <summary>
Expand All @@ -152,7 +168,7 @@ public virtual IContractLogic<TEntity, TContract, TContract, TContract, long> Ge
public virtual IContractLogic<TEntity, TEntity, TEntity, TEntity, long> GetLongReadableLogic<TEntity>(LogicOptions logicOptions = default)
where TEntity : class
{
return GetInternalLongContractLogic<TEntity, TEntity, TEntity, TEntity>(logicOptions);
return GetInternalLongContractLogic<TEntity, TEntity, TEntity, TEntity>(GetLogicOptions(logicOptions));
}

/// <summary>
Expand All @@ -165,7 +181,7 @@ public virtual IContractLogic<TEntity, TContract, TContract, TContract, long> Ge
where TContract : class
where TEntity : class
{
return GetInternalLongContractLogic<TEntity, TContract, TContract, TContract>(logicOptions);
return GetInternalLongContractLogic<TEntity, TContract, TContract, TContract>(GetLogicOptions(logicOptions));
}

/// <summary>
Expand All @@ -177,7 +193,7 @@ public virtual IContractLogic<TEntity, TContract, TContract, TContract, long> Ge
public virtual IContractLogic<TEntity, TEntity, TEntity, TEntity, TId> GetLogic<TEntity, TId>(LogicOptions logicOptions = default)
where TEntity : class
{
return AddDisposable(new IdSchemaDatabaseMappedLogicBase<TEntity, TEntity, TEntity, TEntity, TId>(GetDatabase().GetReadableOf<TEntity>(), GetDatabase().GetWritableOf<TEntity>(), this, logicOptions));
return AddDisposable(new IdSchemaDatabaseMappedLogicBase<TEntity, TEntity, TEntity, TEntity, TId>(GetDatabase().GetReadableOf<TEntity>(), GetDatabase().GetWritableOf<TEntity>(), this, GetLogicOptions(logicOptions)));
}

/// <summary>
Expand All @@ -191,7 +207,7 @@ public virtual IContractLogic<TEntity, TContract, TContract, TContract, TId> Get
where TContract : class
where TEntity : class
{
return AddDisposable(new IdSchemaDatabaseMappedLogicBase<TEntity, TContract, TContract, TContract, TId>(GetDatabase().GetReadableOf<TEntity>(), GetDatabase().GetWritableOf<TEntity>(), this, logicOptions));
return AddDisposable(new IdSchemaDatabaseMappedLogicBase<TEntity, TContract, TContract, TContract, TId>(GetDatabase().GetReadableOf<TEntity>(), GetDatabase().GetWritableOf<TEntity>(), this, GetLogicOptions(logicOptions)));
}


Expand All @@ -204,7 +220,7 @@ public virtual IContractLogic<TEntity, TContract, TContract, TContract, TId> Get
public virtual IContractLogic<TEntity, TEntity, TEntity, TEntity, TId> GetReadableLogic<TEntity, TId>(LogicOptions logicOptions = default)
where TEntity : class
{
return AddDisposable(new IdSchemaDatabaseMappedLogicBase<TEntity, TEntity, TEntity, TEntity, TId>(GetDatabase().GetReadableOf<TEntity>(), this, logicOptions));
return AddDisposable(new IdSchemaDatabaseMappedLogicBase<TEntity, TEntity, TEntity, TEntity, TId>(GetDatabase().GetReadableOf<TEntity>(), this, GetLogicOptions(logicOptions)));
}

/// <summary>
Expand All @@ -218,7 +234,7 @@ public virtual IContractLogic<TEntity, TContract, TContract, TContract, TId> Get
where TContract : class
where TEntity : class
{
return AddDisposable(new IdSchemaDatabaseMappedLogicBase<TEntity, TContract, TContract, TContract, TId>(GetDatabase().GetReadableOf<TEntity>(), this, logicOptions));
return AddDisposable(new IdSchemaDatabaseMappedLogicBase<TEntity, TContract, TContract, TContract, TId>(GetDatabase().GetReadableOf<TEntity>(), this, GetLogicOptions(logicOptions)));
}

/// <summary>
Expand All @@ -233,7 +249,7 @@ public virtual IContractLogic<TEntity, TContract, TCreateRequestContract, TContr
where TContract : class
where TEntity : class
{
return GetInternalLongContractLogic<TEntity, TContract, TCreateRequestContract, TContract>(logicOptions);
return GetInternalLongContractLogic<TEntity, TContract, TCreateRequestContract, TContract>(GetLogicOptions(logicOptions));
}

/// <summary>
Expand All @@ -249,7 +265,7 @@ public virtual IContractLogic<TEntity, TCreateRequestContract, TUpdateRequestCon
where TResponseContract : class
where TEntity : class
{
return GetInternalLongContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract>(logicOptions);
return GetInternalLongContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract>(GetLogicOptions(logicOptions));
}

/// <summary>
Expand All @@ -266,21 +282,21 @@ public virtual IContractLogic<TEntity, TCreateRequestContract, TUpdateRequestCon
where TResponseContract : class
where TEntity : class
{
return GetInternalContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId>(logicOptions);
return GetInternalContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId>(GetLogicOptions(logicOptions));
}

IContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, long> GetInternalLongContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract>(LogicOptions logicOptions = default)
where TResponseContract : class
where TEntity : class
{
return AddDisposable(new LongIdMappedDatabaseLogicBase<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract>(AddDisposable(GetDatabase().GetReadableOf<TEntity>()), AddDisposable(GetDatabase().GetWritableOf<TEntity>()), this, logicOptions));
return AddDisposable(new LongIdMappedDatabaseLogicBase<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract>(AddDisposable(GetDatabase().GetReadableOf<TEntity>()), AddDisposable(GetDatabase().GetWritableOf<TEntity>()), this, GetLogicOptions(logicOptions)));
}

IContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId> GetInternalContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId>(LogicOptions logicOptions = default)
where TResponseContract : class
where TEntity : class
{
return AddDisposable(new IdSchemaDatabaseMappedLogicBase<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId>(AddDisposable(GetDatabase().GetReadableOf<TEntity>()), AddDisposable(GetDatabase().GetWritableOf<TEntity>()), this, logicOptions));
return AddDisposable(new IdSchemaDatabaseMappedLogicBase<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId>(AddDisposable(GetDatabase().GetReadableOf<TEntity>()), AddDisposable(GetDatabase().GetWritableOf<TEntity>()), this, GetLogicOptions(logicOptions)));
}

#endregion
Expand Down Expand Up @@ -444,6 +460,7 @@ public virtual async Task<string> GetCurrentUserUniqueIdentity(LogicOptions logi
var httpContext = ServiceProvider.GetService<IHttpContextAccessor>()?.HttpContext;
if (httpContext != null)
{
logicOptions = GetLogicOptions(logicOptions);
var uniqueIdentity = httpContext.User.FindFirst(nameof(IUniqueIdentitySchema.UniqueIdentity))?.Value;
if (uniqueIdentity.HasValue() && logicOptions.UniqueIdentityStrategy != DataTypes.UniqueIdentityStrategy.Default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.47</Version>
<Version>0.0.1.48</Version>
<Description>core of database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,client,clients</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net45;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.47</Version>
<Version>0.0.1.48</Version>
<Description>core contracts.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,contract,contracts,dto,dtos</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net45;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.47</Version>
<Version>0.0.1.48</Version>
<Description>core of database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.1;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.47</Version>
<Version>0.0.1.48</Version>
<Description>ef core of database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,ef,efcore</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.47</Version>
<Version>0.0.1.48</Version>
<Description>ef core of Relational database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,ef,efcore,Relational</PackageTags>
Expand Down

0 comments on commit 730e43d

Please sign in to comment.