Skip to content
Permalink
Browse files

Removing MongoDbConnection.FromConfig

If an application needs it, it could implement its own helper to get the value and pass it into FromConnectionString
  • Loading branch information...
Turnerj committed Nov 4, 2019
1 parent 6b555e8 commit ac77903d4d16088e337bd657624ce090c970731b
@@ -88,7 +88,7 @@ public class MyContext : MongoDbContext
While it mostly feels the same as creating contexts in Entity Framework, there are a number of differences still with the biggest being in the creation of contexts.
The `IMongoDbConnection` is the core infrastructure that allows connection to MongoDB and is required to instantiate a context.

You can create an instance of a connection in many ways:
You can create an instance of a connection in two ways:
```csharp
IMongoDbConnection connection;
@@ -97,9 +97,6 @@ connection = MongoDbConnection.FromUrl(new MongoUrl("mongodb://localhost:27017/M
//FromConnectionString
connection = MongoDbConnection.FromConnectionString("mongodb://localhost:27017/MyDatabase");
//FromConfig (Note: .NET Framework only)
connection = MongoDbConnection.FromConfig("MyConnectionStringName");
```

### Special Queries
@@ -50,21 +50,6 @@ public static MongoDbConnection FromConnectionString(string connectionString)
return FromUrl(new MongoUrl(connectionString));
}

#if (!NETCOREAPP2_0 && !NETCOREAPP3_0)
public static MongoDbConnection FromConfig(string connectionName)
{
var connectionStringConfig = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName];

if (connectionStringConfig != null)
{
var mongoUrl = MongoUrl.Create(connectionStringConfig.ConnectionString);
return FromUrl(mongoUrl);
}

return null;
}
#endif

public IMongoDatabase GetDatabase()
{
if (IsDisposed)
@@ -8,14 +8,6 @@
<PackageTags>$(PackageBaseTags)</PackageTags>
<Authors>James Turner</Authors>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='NETCOREAPP2_0'">
<DefineConstants>NETCOREAPP2_0</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='netcoreapp3.0'">
<DefineConstants>NETCOREAPP3_0</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.9.2" />
@@ -6,21 +6,6 @@ namespace MongoFramework.Tests
[TestClass]
public class MongoDbConnectionTests
{
#if (!NETCOREAPP2_0 && !NETCOREAPP3_0)
[TestMethod]
public void ConnectionFromConfig()
{
var connection = MongoDbConnection.FromConfig("MongoFrameworkTests");
Assert.IsNotNull(connection);
}
[TestMethod]
public void InvalidConfigForConnection()
{
var connection = MongoDbConnection.FromConfig("ThisConfigNameDoesntExist");
Assert.IsNull(connection);
}
#endif

[TestMethod]
public void ConnectionFromConnectionString()
{
@@ -7,14 +7,6 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='netcoreapp2.1'">
<DefineConstants>NETCOREAPP2_0</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='netcoreapp3.0'">
<DefineConstants>NETCOREAPP3_0</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />

0 comments on commit ac77903

Please sign in to comment.
You can’t perform that action at this time.