Beispiel #1
0
        public EventAppender(EventGraph graph, EventDocumentStorage builder, IInlineProjection[] projections)
        {
            _graph       = graph;
            _builder     = builder;
            _projections = projections;

            // TODO -- track the event streams separately within the DocumentSessionBase
        }
Beispiel #2
0
        public DocumentProvider <T> StorageFor <T>()
        {
            var documentType = typeof(T);

            if (_storage.TryFind(documentType, out var stored))
            {
                return(stored.As <DocumentProvider <T> >());
            }

            if (documentType == typeof(IEvent))
            {
                var storage = new EventDocumentStorage(_options.Events, new EventQueryMapping(_options), _options.Serializer());
                var slot    = new DocumentProvider <IEvent>
                {
                    DirtyTracking = storage,
                    Lightweight   = storage,
                    IdentityMap   = storage,
                    QueryOnly     = storage
                };

                _storage = _storage.AddOrUpdate(documentType, slot);

                return(slot.As <DocumentProvider <T> >());
            }

            var mapping = _options.Storage.FindMapping(documentType);

            if (mapping is DocumentMapping m)
            {
                var builder = new DocumentPersistenceBuilder(m, _options);
                var slot    = builder.Generate <T>();

                _storage = _storage.AddOrUpdate(documentType, slot);

                return(slot);
            }

            if (mapping is SubClassMapping s)
            {
                var loader =
                    typeof(SubClassLoader <, ,>).CloseAndBuildAs <ISubClassLoader <T> >(mapping.Root.DocumentType, documentType,
                                                                                        mapping.IdType);

                var slot = loader.BuildPersistence(this, s);
                _storage = _storage.AddOrUpdate(documentType, slot);

                return(slot);
            }

            if (mapping is EventMapping em)
            {
                var storage = (IDocumentStorage <T>)em;
                var slot    = new DocumentProvider <T> {
                    Lightweight = storage, IdentityMap = storage, DirtyTracking = storage, QueryOnly = storage
                };
                _storage = _storage.AddOrUpdate(documentType, slot);

                return(slot);
            }

            throw new NotSupportedException("Unable to build document persistence handlers for " + mapping.DocumentType.FullNameInCode());
        }