public IDocumentStorage StorageFor(Type documentType) { return(_documentTypes.GetOrAdd(documentType, type => { if (type.Closes(typeof(Stream <>))) { var aggregateType = type.GetGenericArguments().Single(); return Events.StreamMappingFor(aggregateType); } var mapping = MappingFor(documentType); if (mapping is IDocumentStorage) { return mapping.As <IDocumentStorage>(); } assertNoDuplicateDocumentAliases(); IDocumentStorage storage = null; var prebuiltType = StoreOptions.PreBuiltStorage .FirstOrDefault(x => x.DocumentTypeForStorage() == documentType); storage = prebuiltType != null ? DocumentStorageBuilder.BuildStorageObject(this, prebuiltType, mapping.As <DocumentMapping>()) : mapping.BuildStorage(this); _creation.CreateSchema(this, mapping, () => mapping.ShouldRegenerate(this)); return storage; })); }
public IDocumentStorage StorageFor(Type documentType) { return(_documentTypes.GetOrAdd(documentType, type => { var mapping = MappingFor(documentType); if (mapping is IDocumentStorage) { buildSchemaObjectsIfNecessary(mapping); return mapping.As <IDocumentStorage>(); } assertNoDuplicateDocumentAliases(); IDocumentStorage storage = null; var prebuiltType = StoreOptions.PreBuiltStorage .FirstOrDefault(x => x.DocumentTypeForStorage() == documentType); storage = prebuiltType != null ? DocumentStorageBuilder.BuildStorageObject(this, prebuiltType, mapping.As <DocumentMapping>()) : mapping.BuildStorage(this); buildSchemaObjectsIfNecessary(mapping); return storage; })); }