Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Added global config option to allow configuration of ssl settings #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions MongoRepository/GlobalConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MongoRepository
{
public static class GlobalConfig
{
private static Action<SslSettings> ConfigureSslSettingsAction { get; set; }

public static void ConfigureSslSettings(Action<SslSettings> configureSslSettings)
{
ConfigureSslSettingsAction = configureSslSettings;
}

internal static SslSettings GetSslSettings(SslSettings settings)
{
if (settings == null)
{
settings = new SslSettings();
}

ConfigureSslSettingsAction?.Invoke(settings);

return settings;
}
}
}
1 change: 1 addition & 0 deletions MongoRepository/MongoRepository.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<ItemGroup>
<Compile Include="CollectionName.cs" />
<Compile Include="Entity.cs" />
<Compile Include="GlobalConfig.cs" />
<Compile Include="IEntity.cs" />
<Compile Include="RepositoryManager\IRepositoryManager.cs" />
<Compile Include="RepositoryManager\MongoRepositoryManager.cs" />
Expand Down
1 change: 1 addition & 0 deletions MongoRepository/MongoRepository.Net40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<ItemGroup>
<Compile Include="CollectionName.cs" />
<Compile Include="Entity.cs" />
<Compile Include="GlobalConfig.cs" />
<Compile Include="IEntity.cs" />
<Compile Include="RepositoryManager\IRepositoryManager.cs" />
<Compile Include="RepositoryManager\MongoRepositoryManager.cs" />
Expand Down
1 change: 1 addition & 0 deletions MongoRepository/MongoRepository.Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<ItemGroup>
<Compile Include="CollectionName.cs" />
<Compile Include="Entity.cs" />
<Compile Include="GlobalConfig.cs" />
<Compile Include="IEntity.cs" />
<Compile Include="RepositoryManager\IRepositoryManager.cs" />
<Compile Include="RepositoryManager\MongoRepositoryManager.cs" />
Expand Down
6 changes: 5 additions & 1 deletion MongoRepository/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using MongoDB.Driver;
using System;
using System.Configuration;
using System.Security.Authentication;

/// <summary>
/// Internal miscellaneous utility functions.
Expand Down Expand Up @@ -30,7 +31,10 @@ public static string GetDefaultConnectionString()
/// <returns>Returns a MongoDatabase from the specified url.</returns>
private static MongoDatabase GetDatabaseFromUrl(MongoUrl url)
{
var client = new MongoClient(url);
var settings = MongoClientSettings.FromUrl(url);
settings.SslSettings = GlobalConfig.GetSslSettings(settings.SslSettings);

var client = new MongoClient(settings);
var server = client.GetServer();
return server.GetDatabase(url.DatabaseName); // WriteConcern defaulted to Acknowledged
}
Expand Down