diff --git a/Source/Bifrost.Events.MongoDB/EventStore.cs b/Source/Bifrost.Events.MongoDB/EventStore.cs index a25477c32..218edcfde 100644 --- a/Source/Bifrost.Events.MongoDB/EventStore.cs +++ b/Source/Bifrost.Events.MongoDB/EventStore.cs @@ -17,6 +17,8 @@ namespace Bifrost.Events.MongoDB /// public class EventStore : IEventStore { + const string EventStoreCollectionName = "Events"; + IMongoCollection _collection; static EventStore() @@ -27,9 +29,15 @@ static EventStore() /// /// Initializes a new instance of /// - public EventStore() + /// Connection details provider + public EventStore(ICanProvideConnectionDetails connectionDetailsProvider) { _collection = null; + var connectionDetails = connectionDetailsProvider(); + var settings = MongoClientSettings.FromUrl(new MongoUrl(connectionDetails.Item1)); + var client = new MongoClient(settings); + var database = client.GetDatabase(connectionDetails.Item2); + _collection = database.GetCollection(EventStoreCollectionName); } /// diff --git a/Source/Bifrost.Events.MongoDB/EventStoreConfigurationExtensions.cs b/Source/Bifrost.Events.MongoDB/EventStoreConfigurationExtensions.cs new file mode 100644 index 000000000..2053cc7c8 --- /dev/null +++ b/Source/Bifrost.Events.MongoDB/EventStoreConfigurationExtensions.cs @@ -0,0 +1,30 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) 2008-2017 Dolittle. All rights reserved. + * Licensed under the MIT License. See LICENSE in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +using System; +using Bifrost.Configuration; +using Bifrost.Events.MongoDB; + +namespace Bifrost.Events +{ + /// + /// Extensions for configuring + /// + public static class EventStoreConfigurationExtensions + { + /// + /// Configures to be using Azure Tables + /// + /// to configure + /// ConnectionString for connecting to your Azure Storage account + /// Name of Database + /// Chained + public static EventStoreConfiguration UsingTables(this EventStoreConfiguration eventStoreConfiguration, string connectionString, string databaseName) + { + eventStoreConfiguration.EventStore = typeof(EventStore); + Configure.Instance.Container.Bind(() => new Tuple(connectionString, databaseName)); + return eventStoreConfiguration; + } + } +} diff --git a/Source/Bifrost.Events.MongoDB/ICanProvideConnectionDetails.cs b/Source/Bifrost.Events.MongoDB/ICanProvideConnectionDetails.cs new file mode 100644 index 000000000..6a0f289bd --- /dev/null +++ b/Source/Bifrost.Events.MongoDB/ICanProvideConnectionDetails.cs @@ -0,0 +1,14 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) 2008-2017 Dolittle. All rights reserved. + * Licensed under the MIT License. See LICENSE in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +using System; + +namespace Bifrost.Events.MongoDB +{ + /// + /// Delegate for providing connection string for + /// + /// + public delegate Tuple ICanProvideConnectionDetails(); +}