ContextCore / GridDomain

Framework for building domain-centric robust, scalable and reliable applications with ease
18 stars 7 forks source link

Add simpler custom aggregate factories #76

Open andreyleskov opened 6 years ago

andreyleskov commented 6 years ago

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);
        }
    }