Esempio n. 1
0
        internal EventSourcedEntityHandler(AnySupport anySupport, IEventSourcedContext context, IBehaviorResolver behaviorReflectionCache, Func <IEventSourcedEntityCreationContext, object> entityCreationFactory = null)
        {
            AnySupport              = anySupport;
            Context                 = context;
            EntityCreationFactory   = entityCreationFactory;
            BehaviorReflectionCache = behaviorReflectionCache;

            var explicitBehaviors = Option.None <object[]>();
            var active            = true;

            void Become(object[] behaviors)
            {
                // ReSharper disable once AccessToModifiedClosure
                if (!active)
                {
                    throw new InvalidOperationException("Context is not active!");
                }
                explicitBehaviors = Option.Some(ValidateBehaviors(behaviors).ToArray());
            }

            var ctx    = new EventSourcedEntityCreationContext(context, Become);
            var entity = EntityCreationFactory(ctx);

            active           = false;
            CurrentBehaviors = explicitBehaviors.Match(behaviors => behaviors, () => new[] { entity });
        }
 public IEventSourcedEntityHandler CreateEntityHandler(IEventSourcedContext ctx)
 {
     return(new EventSourcedEntityHandler(
                AnySupport,
                ctx,
                BehaviorResolver,
                x => Factory.Invoke(x)
                ));
 }
 public ShouldSupportMultiArgConstructor(IEventSourcedContext context, [EntityId] string entityId)
 {
     Assert.Equal("foo", context.EntityId);
     Assert.Equal("foo", entityId);
 }
 public CreationContextArgConstructorEntity(IEventSourcedContext context)
 {
     Assert.Equal("foo", context.EntityId);
 }
 public UnsupportedMultipleConstructorsParameterEntity(IEventSourcedContext context)
 {
 }
Esempio n. 6
0
 public MultiArgCommandHandlerEntity(IEventSourcedContext ctx)
 {
     Ctx = ctx;
     Eid = ctx.EntityId;
 }
Esempio n. 7
0
 public EventSourcedEntityCreationContext(IEventSourcedContext @delegate, Action <object[]> become)
     : base(@delegate)
 {
     Become = become;
 }