-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[linqpad6] Support appsettings.json for typed data context (#52)
* [LINQPAD6] add support for appsettings.json for static connection * release notes
- Loading branch information
Showing
6 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#if NETCORE | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using LinqToDB.Configuration; | ||
|
||
namespace LinqToDB.LINQPad | ||
{ | ||
internal class AppJsonConfig : ILinqToDBSettings | ||
{ | ||
public static ILinqToDBSettings Load(string configPath) | ||
{ | ||
var config = JsonSerializer.Deserialize<JsonConfig>(File.ReadAllText(configPath)); | ||
|
||
return new AppJsonConfig(config?.ConnectionStrings?.Select(entry => (IConnectionStringSettings)new ConnectionStringSettings(entry.Key, entry.Value)).ToArray() | ||
?? Array.Empty<IConnectionStringSettings>()); | ||
} | ||
|
||
private readonly IConnectionStringSettings[] _connectionStrings; | ||
|
||
public AppJsonConfig(IConnectionStringSettings[] connectionStrings) | ||
{ | ||
_connectionStrings = connectionStrings; | ||
} | ||
|
||
IEnumerable<IDataProviderSettings> ILinqToDBSettings.DataProviders => Array.Empty<IDataProviderSettings>(); | ||
string? ILinqToDBSettings.DefaultConfiguration => null; | ||
string? ILinqToDBSettings.DefaultDataProvider => null; | ||
IEnumerable<IConnectionStringSettings> ILinqToDBSettings.ConnectionStrings => _connectionStrings; | ||
|
||
private class JsonConfig | ||
{ | ||
public IDictionary<string, string>? ConnectionStrings { get; set; } | ||
} | ||
|
||
private class ConnectionStringSettings : IConnectionStringSettings | ||
{ | ||
private readonly string _name; | ||
private readonly string _connectionString; | ||
|
||
public ConnectionStringSettings(string name, string connectionString) | ||
{ | ||
_name = name; | ||
_connectionString = connectionString; | ||
} | ||
|
||
string IConnectionStringSettings.ConnectionString => _connectionString; | ||
string IConnectionStringSettings.Name => _name; | ||
string? IConnectionStringSettings.ProviderName => null; | ||
bool IConnectionStringSettings.IsGlobal => false; | ||
} | ||
} | ||
} | ||
#endif |
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
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
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
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