Skip to content

Add simpler custom aggregate factories  #76

Description

@andreyleskov

Add a base class for user-defined aggregate factories specialized for specific instantiation of the only one user-defined aggregate. It will reduce the boilerplate code for user, the check for a concrete type. Current custom factory example:

 public class BinaryOptionAggregateFactory : IConstructAggregates
    {
        private readonly IPriceProvider _provider;

        public BinaryOptionAggregateFactory(IPriceProvider provider)
        {
            _provider = provider;
        }
        public IAggregate Build(Type type, string id, IMemento snapshot = null)
        {
           if(type == typeof(BinaryOptionGame))
               return new BinaryOptionGame(id,_provider);

            return AggregateFactory.Default.Build(type, id, snapshot);
        }
    }

Idea of an improved factory:

 public class BinaryOptionAggregateFactory : AggregateFactory<BinaryOptionGame>
    {
        private readonly IPriceProvider _provider;

        public BinaryOptionAggregateFactory(IPriceProvider provider)
        {
            _provider = provider;
        }
        public BinaryOptionGame Build(string id, IMemento snapshot = null)
        {
               return new BinaryOptionGame(id,_provider);
        }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions