Created
July 18, 2016 12:25
-
-
Save nickchampion/0d07d733c6722dd9b687f250b4e5b6c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IDocumentStore Create() | |
{ | |
var store = new DocumentStore | |
{ | |
Url = BootstrapConfiguration.DatabaseUrl, | |
ApiKey = BootstrapConfiguration.WebClientDatabaseApiKey, | |
ResourceManagerId = _resourceManagerId, | |
EnlistInDistributedTransactions = false, | |
Conventions = | |
{ | |
FindTypeTagName = MarketplaceDocumentConvention.DefaultTagTypeName, | |
CustomizeJsonSerializer = serializer => | |
{ | |
serializer.Converters.Add(new DurationConverter()); | |
serializer.Converters.Add(new IgnoreTypesJsonConverter()); | |
} | |
}, | |
}; | |
store.RegisterListener(new IgnoreRevisionsUniqueConstraintsStoreListener()); | |
store.RegisterListener(new UniqueConstraintRemoveMetadataListener()); | |
if (_documentStoreListeners != null && _documentStoreListeners.Any()) | |
{ | |
foreach (var listener in _documentStoreListeners) | |
{ | |
store.RegisterListener(listener); | |
} | |
} | |
if (BootstrapConfiguration.ReplicationEnabled) | |
{ | |
store.Conventions.IndexAndTransformerReplicationMode = BootstrapConfiguration.IndexReplicationEnabled ? | |
IndexAndTransformerReplicationMode.Indexes | IndexAndTransformerReplicationMode.Transformers : | |
IndexAndTransformerReplicationMode.None; | |
store.Conventions.FailoverBehavior = FailoverBehavior.ReadFromAllWriteToLeaderWithFailovers; | |
store.FailoverServers = new FailoverServers(); | |
store.FailoverServers.AddForDatabase(Databases.Marketplace, BootstrapConfiguration.FailoverDatabases.Select( | |
db => new ReplicationDestination | |
{ | |
TransitiveReplicationBehavior = BootstrapConfiguration.ReplicateReplicatedDocuments ? TransitiveReplicationOptions.Replicate : TransitiveReplicationOptions.None, | |
Database = Databases.Marketplace, | |
Url = db, | |
ApiKey = BootstrapConfiguration.WebClientDatabaseApiKey | |
}).ToArray()); | |
store.FailoverServers.AddForDatabase(Databases.Audit, BootstrapConfiguration.FailoverDatabases.Select( | |
db => new ReplicationDestination | |
{ | |
TransitiveReplicationBehavior = BootstrapConfiguration.ReplicateReplicatedDocuments ? TransitiveReplicationOptions.Replicate : TransitiveReplicationOptions.None, | |
Database = Databases.Audit, | |
Url = db, | |
ApiKey = BootstrapConfiguration.WebClientDatabaseApiKey | |
}).ToArray()); | |
} | |
else | |
{ | |
store.Conventions.IndexAndTransformerReplicationMode = IndexAndTransformerReplicationMode.None; | |
store.Conventions.FailoverBehavior = FailoverBehavior.FailImmediately; | |
} | |
store.Initialize(); | |
return store; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment