Exemple #1
0
        /// <summary>
        /// Requires the persistence data context (<see cref="IPersistenceDataContext"/>) for this flow context.
        /// <para>If flow context (<paramref name="ctx"/>) is <see langword="null"/> OR flow context have not a data context (<see cref="DataContextFlowContextProps.DataContextProp"/>, <see cref="DataContextFlowContextProps.HasDataContext(IContext, bool)"/>), then exception describing the persistence data context abscence will be thrown.</para>
        /// <para>If flow context (<paramref name="ctx"/>) has data context, that incompatible with <see cref="IPersistenceDataContext"/>, then exception (see above) will be thrown.</para>
        /// </summary>
        /// <param name="ctx">
        /// Flow context.
        /// <para>Can be <see langword="null"/>.</para>
        /// </param>
        public static IPersistenceDataContext PersistenceDataContext(this IContext ctx)
        {
            IDataContext2 dataCtx = default;

            if (ctx is null || !ctx.HasDataContext(dataCtx: out dataCtx) || !(dataCtx is IPersistenceDataContext persistenceDataCtx))
            {
                throw new EonException(message: $"The persistence data context is missing{(ctx is null ? "." : " in this flow context.")}{(ctx is null ? string.Empty : $"{Environment.NewLine}\tContext:{ctx.FmtStr().GNLI2()}")}{(dataCtx is null ? string.Empty : $"{Environment.NewLine}\tExisting data context (type):{dataCtx.GetType().FmtStr().GNLI2()}")}");
            }
Exemple #2
0
 internal P_Disposable(EfCoreDbContext efContext, IDataContext2 dataContext, ILogger logger, IDependencySupport outerDependencies)
     : base(outerDependencies: outerDependencies)
 {
     //
     efContext.EnsureNotNull(nameof(efContext));
     //
     _efContext       = efContext;
     _efContextString = efContext.ToString();
     _dataContext     = dataContext;
     _logger          = logger;
 }
Exemple #3
0
 protected override void Dispose(bool explicitDispose)
 {
     if (explicitDispose)
     {
         var logger = _logger;
         if (!(logger is null))
         {
             logger
             .LogDebug(
                 eventId: GenericEventIds.ExplicitDispose,
                 message: $"Explicit dispose call.{Environment.NewLine}\tComponent:{Environment.NewLine}\t\t{{component}}",
                 args: new object[] { _efContextString });
         }
     }
     _efContext       = null;
     _dataContext     = null;
     _logger          = null;
     _efContextString = null;
     //
     base.Dispose(explicitDispose);
 }
Exemple #4
0
        public static IContext New(
            this IContext outerCtx,
            IDataContext2 dataCtx,
            XFullCorrelationId fullCorrelationId = default,
            ArgumentPlaceholder <XCorrelationId> correlationId = default,
            object localTag = default,
            ArgumentPlaceholder <CancellationToken> ct = default,
            ArgumentPlaceholder <IVh <IDisposeRegistry> > disposeRegistry        = default,
            ArgumentPlaceholder <IVh <IAsyncProgress <IFormattable> > > progress = default,
            ArgumentPlaceholder <IFormattable> displayName = default)
        {
            //
            var newCtx = default(IContext);

            try {
                newCtx = ContextUtilities.Create(outerCtx: outerCtx, fullCorrelationId: fullCorrelationId, correlationId: correlationId, localTag: localTag, ct: ct, disposeRegistry: disposeRegistry, progress: progress, displayName: displayName);
                DataContextFlowContextProps.DataContextProp.SetLocalValue(ctx: newCtx, value: dataCtx);
                return(newCtx);
            }
            catch (Exception exception) {
                newCtx?.Dispose(exception);
                throw;
            }
        }