Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new instance of <see cref="RavenChildProjector{TProjection}"/>.
 /// </summary>
 /// <param name="mapBuilder">
 /// The <see cref="IEventMapBuilder{TProjection,TKey,TContext}"/>
 /// with already configured handlers for all the required events
 /// but not yet configured how to handle custom actions, projection creation, updating and deletion.
 /// The <see cref="IEventMap{TContext}"/> will be created from it.
 /// </param>
 /// <param name="setIdentity">
 /// Is used by the projector to set the identity of the projection.
 /// </param>
 /// <param name="children">An optional collection of <see cref="IRavenChildProjector"/> which project events
 /// in the same session just before the parent projector.</param>
 public RavenChildProjector(
     IEventMapBuilder <TProjection, string, RavenProjectionContext> mapBuilder,
     Action <TProjection, string> setIdentity,
     IEnumerable <IRavenChildProjector> children = null)
 {
     mapConfigurator = new RavenEventMapConfigurator <TProjection>(mapBuilder, setIdentity, children);
 }
        public ExampleProjector(IEventMapBuilder <TProjection, string, ProjectionContext> mapBuilder, InMemoryDatabase store, params IExampleProjector[] childProjectors)
        {
            this.store = store;
            var map = BuildMapFrom(mapBuilder);

            innerProjector = new Projector(map, childProjectors.Select(p => p.InnerProjector));
        }
        private IEventMap <ProjectionContext> BuildMapFrom(IEventMapBuilder <TProjection, string, ProjectionContext> mapBuilder)
        {
            mapBuilder.HandleProjectionModificationsAs((key, context, projector, options) =>
            {
                TProjection projection = store.GetRepository <TProjection>().Find(key);
                if (projection == null)
                {
                    projection = new TProjection()
                    {
                        Id = key
                    };

                    store.Add(projection);
                }

                return(projector(projection));
            });

            mapBuilder.HandleProjectionDeletionsAs((key, context, options) =>
            {
                store.GetRepository <TProjection>().RemoveByKey(key);

                return(Task.FromResult(0));
            });

            mapBuilder.HandleCustomActionsAs((context, projector) => projector());

            return(mapBuilder.Build());
        }
Ejemplo n.º 4
0
        private IEventMap <ProjectionContext> BuildMapFrom(IEventMapBuilder <TProjection, string, ProjectionContext> mapBuilder)
        {
            return(mapBuilder.Build(new ProjectorMap <TProjection, string, ProjectionContext>
            {
                Create = async(key, context, projector, shouldOverride) =>
                {
                    var projection = new TProjection()
                    {
                        Id = key
                    };

                    await projector(projection);

                    store.Add(projection);
                },
                Update = async(key, context, projector, createIfMissing) =>
                {
                    TProjection projection = store.GetRepository <TProjection>().Find(key);
                    await projector(projection);

                    store.Add(projection);
                },
                Delete = (key, context) =>
                {
                    store.GetRepository <TProjection>().RemoveByKey(key);

                    return Task.FromResult(true);
                },
                Custom = (context, projector) => projector()
            }));
        }
 /// <summary>
 /// Creates a new instance of <see cref="NHibernateProjector{TProjection,TKey,TState}"/>.
 /// </summary>
 /// <param name="sessionFactory">The delegate that creates a new <see cref="ISession"/>.</param>
 /// <param name="mapBuilder">
 /// The <see cref="IEventMapBuilder{TProjection,TKey,TContext}"/>
 /// with already configured handlers for all the required events
 /// but not yet configured how to handle custom actions, projection creation, updating and deletion.
 /// The <see cref="IEventMap{TContext}"/> will be created from it.
 /// </param>
 /// <param name="children">An optional collection of <see cref="INHibernateChildProjector"/> which project events
 /// in the same transaction just before the parent projector.</param>
 public NHibernateProjector(
     Func <ISession> sessionFactory,
     IEventMapBuilder <TProjection, TKey, NHibernateProjectionContext> mapBuilder, Action <TProjection, TKey> setIdentity,
     IEnumerable <INHibernateChildProjector> children = null)
 {
     this.sessionFactory = sessionFactory;
     mapConfigurator     = new NHibernateEventMapConfigurator <TProjection, TKey>(mapBuilder, setIdentity, children);
 }
 public EntityFrameworkEventMapConfigurator(
     IEventMapBuilder <TProjection, TKey, EntityFrameworkProjectionContext> eventMapBuilder,
     Action <TProjection, TKey> setIdentity)
 {
     _setIdentity     = setIdentity ?? throw new ArgumentNullException(nameof(setIdentity));
     _eventMapBuilder = eventMapBuilder ?? throw new ArgumentNullException(nameof(eventMapBuilder));
     _eventMap        = BuildEventMap(eventMapBuilder);
 }
Ejemplo n.º 7
0
 public EntityFrameworkProjector(
     Func <DbContext> dbContextFactory,
     IEventMapBuilder <TProjection, TKey, EntityFrameworkProjectionContext> mapBuilder,
     Action <TProjection, TKey> setIdentity)
 {
     _dbContextFactory = dbContextFactory ?? throw new ArgumentNullException(nameof(dbContextFactory));
     _mapConfigurator  = new EntityFrameworkEventMapConfigurator <TProjection, TKey>(mapBuilder, setIdentity);
 }
Ejemplo n.º 8
0
 private IEventMap <NHibernateProjectionContext> BuildMap(
     IEventMapBuilder <TProjection, TKey, NHibernateProjectionContext> mapBuilder)
 {
     mapBuilder.HandleCustomActionsAs((_, projector) => projector());
     mapBuilder.HandleProjectionModificationsAs(HandleProjectionModification);
     mapBuilder.HandleProjectionDeletionsAs(HandleProjectionDeletion);
     return(mapBuilder.Build());
 }
Ejemplo n.º 9
0
        private static IEventMap <ProjectionContext> BuildMap(IEventMapBuilder <ProjectionContext> eventMapBuilder)
        {
            if (eventMapBuilder == null)
            {
                throw new ArgumentNullException(nameof(eventMapBuilder));
            }

            SetupHandlers(eventMapBuilder);
            return(eventMapBuilder.Build());
        }
 private IEventMap <EntityFrameworkProjectionContext> BuildEventMap(
     IEventMapBuilder <TProjection, TKey, EntityFrameworkProjectionContext> mapBuilder)
 {
     return(mapBuilder.Build(new ProjectorMap <TProjection, TKey, EntityFrameworkProjectionContext>
     {
         Create = OnCreate,
         Update = OnUpdate,
         Delete = OnDelete,
         Custom = (context, projector) => projector()
     }));
 }
Ejemplo n.º 11
0
        public NHibernateEventMapConfigurator(
            IEventMapBuilder <TProjection, TKey, NHibernateProjectionContext> mapBuilder,
            IEnumerable <INHibernateChildProjector> children = null)
        {
            if (mapBuilder == null)
            {
                throw new ArgumentNullException(nameof(mapBuilder));
            }

            map           = BuildMap(mapBuilder);
            this.children = children?.ToList() ?? new List <INHibernateChildProjector>();
        }
Ejemplo n.º 12
0
        private static IEventMap <ProjectionContext> BuildMap(IEventMapBuilder <ProjectionContext> eventMapBuilder)
        {
            if (eventMapBuilder == null)
            {
                throw new ArgumentNullException(nameof(eventMapBuilder));
            }

            return(eventMapBuilder.Build(new ProjectorMap <ProjectionContext>
            {
                Custom = (context, projector) => projector()
            }));
        }
        public RavenEventMapConfigurator(
            IEventMapBuilder <TProjection, string, RavenProjectionContext> mapBuilder,
            IEnumerable <IRavenChildProjector> children = null)
        {
            if (mapBuilder == null)
            {
                throw new ArgumentNullException(nameof(mapBuilder));
            }

            map           = BuildMap(mapBuilder);
            this.children = children?.ToList() ?? new List <IRavenChildProjector>();
        }
        /// <summary>
        /// Creates a new instance of <see cref="RavenProjector{TProjection}"/>.
        /// </summary>
        /// <param name="sessionFactory">The delegate that creates a new <see cref="IAsyncDocumentSession"/>.</param>
        /// <param name="mapBuilder">
        /// The <see cref="IEventMapBuilder{TProjection,TKey,TContext}"/>
        /// with already configured handlers for all the required events
        /// but not yet configured how to handle custom actions, projection creation, updating and deletion.
        /// The <see cref="IEventMap{TContext}"/> will be created from it.
        /// </param>
        /// <param name="setIdentity">
        /// Is used by the projector to set the identity of the projection.
        /// </param>
        /// <param name="children">An optional collection of <see cref="IRavenChildProjector"/> which project events
        /// in the same session just before the parent projector.</param>
        public RavenProjector(
            Func <IAsyncDocumentSession> sessionFactory,
            IEventMapBuilder <TProjection, string, RavenProjectionContext> mapBuilder,
            Action <TProjection, string> setIdentity,
            IEnumerable <IRavenChildProjector> children = null)
        {
            if (mapBuilder == null)
            {
                throw new ArgumentNullException(nameof(mapBuilder));
            }

            this.sessionFactory = sessionFactory ?? throw new ArgumentNullException(nameof(sessionFactory));
            mapConfigurator     = new RavenEventMapConfigurator <TProjection>(mapBuilder, setIdentity, children);
        }
Ejemplo n.º 15
0
        public Projector(IEventMapBuilder <ProjectionContext> eventMapBuilder, IEnumerable <Projector> children = null)
        {
            if (eventMapBuilder == null)
            {
                throw new ArgumentNullException(nameof(eventMapBuilder));
            }

            SetupHandlers(eventMapBuilder);
            map           = eventMapBuilder.Build();
            this.children = children?.ToList() ?? new List <Projector>();

            if (this.children.Contains(null))
            {
                throw new ArgumentException("There is null child projector.", nameof(children));
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Creates a new instance of <see cref="NHibernateChildProjector{TProjection,TKey}"/>.
 /// </summary>
 /// <param name="mapBuilder">
 /// The <see cref="IEventMapBuilder{TProjection,TKey,TContext}"/>
 /// with already configured handlers for all the required events
 /// but not yet configured how to handle custom actions, projection creation, updating and deletion.
 /// The <see cref="IEventMap{TContext}"/> will be created from it.
 /// </param>
 /// <param name="children">An optional collection of <see cref="INHibernateChildProjector"/> which project events
 /// in the same transaction just before the parent projector.</param>
 public NHibernateChildProjector(
     IEventMapBuilder <TProjection, TKey, NHibernateProjectionContext> mapBuilder,
     IEnumerable <INHibernateChildProjector> children = null)
 {
     mapConfigurator = new NHibernateEventMapConfigurator <TProjection, TKey>(mapBuilder, children);
 }
Ejemplo n.º 17
0
 public InnerProjector(IEventMapBuilder <ProjectionContext> eventMapBuilder, IEnumerable <InnerProjector> children = null)
     : this(BuildMap(eventMapBuilder), children)
 {
 }
Ejemplo n.º 18
0
 private static void SetupHandlers(IEventMapBuilder <ProjectionContext> eventMapBuilder)
 {
     eventMapBuilder.HandleCustomActionsAs((context, projector) => projector());
 }