コード例 #1
0
 public static UnitOfWork <TIdentifier, TEventBase> GetUnitOfWork <TIdentifier, TEventBase>(this CommandHandlingContext context)
     where TIdentifier : IEquatable <TIdentifier>
 => context.Get <UnitOfWork <TIdentifier, TEventBase> >(UnitOfWorkKey);
コード例 #2
0
        public static UnitOfWork <TIdentifier, TEventBase> CreateUnitOfWork <TIdentifier, TEventBase>(this CommandHandlingContext context)
            where TIdentifier : IEquatable <TIdentifier>
        {
            lock (context)
            {
                if (context.GetUnitOfWork <TIdentifier, TEventBase>() != null)
                {
                    throw new InvalidOperationException("Unit of work already created for this context, make sure CommandHandlingContext is registered as scoped service");
                }

                var unitOfWork = new UnitOfWork <TIdentifier, TEventBase>();
                context.Set(UnitOfWorkKey, unitOfWork);
                return(unitOfWork);
            }
        }