public DocumentProvider <T> StorageFor <T>() where T : notnull { var documentType = typeof(T); if (_storage.TryFind(documentType, out var stored)) { return(stored.As <DocumentProvider <T> >()); } if (documentType == typeof(IEvent)) { var slot = EventDocumentStorageGenerator.BuildProvider(_options); _storage = _storage.AddOrUpdate(documentType, slot); return(slot.As <DocumentProvider <T> >()); } var mapping = _options.Storage.FindMapping(documentType); switch (mapping) { case DocumentMapping m: { var builder = new DocumentPersistenceBuilder(m, _options); var slot = builder.Generate <T>(); _storage = _storage.AddOrUpdate(documentType, slot); return(slot); } case 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); } case 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); } default: throw new NotSupportedException("Unable to build document persistence handlers for " + mapping.DocumentType.FullNameInCode()); } }
public void BuildAndStore(Assembly assembly, DocumentMapping mapping, StoreOptions options) { try { var provider = DocumentPersistenceBuilder.FromPreBuiltTypes <T>(assembly, mapping); options.Providers.Append(provider); } catch (Exception) { Console.WriteLine("Unable to use pre-built type for " + typeof(T).FullNameInCode()); } }
public IServiceVariableSource AssemblyTypes(GenerationRules rules, GeneratedAssembly assembly) { // This is important to ensure that all the possible DocumentMappings exist // first Storage.BuildAllMappings(); foreach (var mapping in Storage.AllDocumentMappings) { var builder = new DocumentPersistenceBuilder(mapping, this); builder.AssemblyTypes(assembly); } if (_compiledQueryTypes.Any()) { using var session = new LightweightSession(this); foreach (var compiledQueryType in _compiledQueryTypes) { var plan = QueryCompiler.BuildPlan(session, compiledQueryType, this); var builder = new CompiledQuerySourceBuilder(plan, this); builder.AssemblyType(assembly); } } return(null); }
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()); }
public void BuildAndStore(Assembly assembly, DocumentMapping mapping, StoreOptions options) { var provider = DocumentPersistenceBuilder.FromPreBuiltTypes <T>(assembly, mapping); options.Providers.Append(provider); }
private DocumentPersistence <T> CreateSlot() { var builder = new DocumentPersistenceBuilder(Mapping, Options); return(builder.Generate <T>()); }