-
Notifications
You must be signed in to change notification settings - Fork 217
/
NpgsqlSingletonOptions.cs
140 lines (121 loc) · 7.41 KB
/
NpgsqlSingletonOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System.Data.Common;
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Internal;
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public class NpgsqlSingletonOptions : INpgsqlSingletonOptions
{
/// <inheritdoc />
public virtual Version PostgresVersion { get; private set; } = null!;
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool IsPostgresVersionSet { get; private set; }
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool UseRedshift { get; private set; }
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool ReverseNullOrderingEnabled { get; private set; }
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual DbDataSource? DataSource { get; private set; }
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IReadOnlyList<UserRangeDefinition> UserRangeDefinitions { get; private set; }
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IServiceProvider? ApplicationServiceProvider { get; private set; }
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public NpgsqlSingletonOptions()
{
UserRangeDefinitions = [];
}
/// <inheritdoc />
public virtual void Initialize(IDbContextOptions options)
{
var npgsqlOptions = options.FindExtension<NpgsqlOptionsExtension>() ?? new NpgsqlOptionsExtension();
var coreOptions = options.FindExtension<CoreOptionsExtension>() ?? new CoreOptionsExtension();
PostgresVersion = npgsqlOptions.PostgresVersion;
IsPostgresVersionSet = npgsqlOptions.IsPostgresVersionSet;
UseRedshift = npgsqlOptions.UseRedshift;
ReverseNullOrderingEnabled = npgsqlOptions.ReverseNullOrdering;
UserRangeDefinitions = npgsqlOptions.UserRangeDefinitions;
// TODO: Remove after https://github.com/dotnet/efcore/pull/29950
ApplicationServiceProvider = coreOptions.ApplicationServiceProvider;
DataSource = npgsqlOptions.DataSource ?? (npgsqlOptions.ConnectionString is null && npgsqlOptions.Connection is null
? coreOptions.ApplicationServiceProvider?.GetService<NpgsqlDataSource>()
: null);
}
/// <inheritdoc />
public virtual void Validate(IDbContextOptions options)
{
var npgsqlOptions = options.FindExtension<NpgsqlOptionsExtension>() ?? new NpgsqlOptionsExtension();
if (PostgresVersion != npgsqlOptions.PostgresVersion)
{
throw new InvalidOperationException(
CoreStrings.SingletonOptionChanged(
nameof(NpgsqlDbContextOptionsBuilder.SetPostgresVersion),
nameof(DbContextOptionsBuilder.UseInternalServiceProvider)));
}
if (UseRedshift != npgsqlOptions.UseRedshift)
{
throw new InvalidOperationException(
CoreStrings.SingletonOptionChanged(
nameof(NpgsqlDbContextOptionsBuilder.UseRedshift),
nameof(DbContextOptionsBuilder.UseInternalServiceProvider)));
}
if (ReverseNullOrderingEnabled != npgsqlOptions.ReverseNullOrdering)
{
throw new InvalidOperationException(
CoreStrings.SingletonOptionChanged(
nameof(NpgsqlDbContextOptionsBuilder.ReverseNullOrdering),
nameof(DbContextOptionsBuilder.UseInternalServiceProvider)));
}
if (npgsqlOptions.DataSource is not null && !ReferenceEquals(DataSource, npgsqlOptions.DataSource))
{
throw new InvalidOperationException(
NpgsqlStrings.TwoDataSourcesInSameServiceProvider(nameof(DbContextOptionsBuilder.UseInternalServiceProvider)));
}
if (!UserRangeDefinitions.SequenceEqual(npgsqlOptions.UserRangeDefinitions))
{
throw new InvalidOperationException(
CoreStrings.SingletonOptionChanged(
nameof(NpgsqlDbContextOptionsBuilder.MapRange),
nameof(DbContextOptionsBuilder.UseInternalServiceProvider)));
}
}
}