Skip to content

Commit 6a4a951

Browse files
committed
Merge branch 'rel/2.0.0-preview2' into dev
2 parents 3075c74 + e900873 commit 6a4a951

33 files changed

+366
-108
lines changed

src/EFCore.Design/Design/Internal/DatabaseOperations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public virtual Task<ReverseEngineerFiles> ScaffoldContextAsync(
6262
loggerFactory.AddProvider(new LoggerProvider(categoryName => new OperationLogger(categoryName, _reporter)));
6363
#pragma warning restore CS0618 // Type or member is obsolete
6464

65-
var generator = services.GetRequiredService<ModelScaffolder>();
65+
var generator = services.GetRequiredService<IModelScaffolder>();
6666

6767
return generator.GenerateAsync(
6868
connectionString,

src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
2020
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
2121
/// directly from your code. This API may change or be removed in future releases.
2222
/// </summary>
23-
public class CSharpDbContextGenerator
23+
public class CSharpDbContextGenerator : ICSharpDbContextGenerator
2424
{
2525
private const string EntityLambdaIdentifier = "entity";
2626

27-
private readonly CSharpUtilities _cSharpUtilities;
27+
private readonly ICSharpUtilities _cSharpUtilities;
2828
private readonly IScaffoldingHelper _scaffoldingHelper;
2929
private readonly IAnnotationRenderer _annotationRenderer;
3030
private IndentedStringBuilder _sb;
@@ -37,7 +37,7 @@ public class CSharpDbContextGenerator
3737
public CSharpDbContextGenerator(
3838
[NotNull] IScaffoldingHelper scaffoldingHelper,
3939
[NotNull] IAnnotationRenderer annotationRenderer,
40-
[NotNull] CSharpUtilities cSharpUtilities)
40+
[NotNull] ICSharpUtilities cSharpUtilities)
4141
{
4242
Check.NotNull(scaffoldingHelper, nameof(scaffoldingHelper));
4343
Check.NotNull(annotationRenderer, nameof(annotationRenderer));
@@ -53,10 +53,10 @@ public CSharpDbContextGenerator(
5353
/// directly from your code. This API may change or be removed in future releases.
5454
/// </summary>
5555
public virtual string WriteCode(
56-
[NotNull] IModel model,
57-
[NotNull] string @namespace,
58-
[NotNull] string contextName,
59-
[NotNull] string connectionString,
56+
IModel model,
57+
string @namespace,
58+
string contextName,
59+
string connectionString,
6060
bool useDataAnnotations)
6161
{
6262
Check.NotNull(model, nameof(model));

src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
1919
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
2020
/// directly from your code. This API may change or be removed in future releases.
2121
/// </summary>
22-
public class CSharpEntityTypeGenerator
22+
public class CSharpEntityTypeGenerator : ICSharpEntityTypeGenerator
2323
{
24-
private CSharpUtilities CSharpUtilities { get; }
24+
private ICSharpUtilities CSharpUtilities { get; }
2525

2626
private IndentedStringBuilder _sb;
2727
private bool _useDataAnnotations;
@@ -31,7 +31,7 @@ public class CSharpEntityTypeGenerator
3131
/// directly from your code. This API may change or be removed in future releases.
3232
/// </summary>
3333
public CSharpEntityTypeGenerator(
34-
[NotNull] CSharpUtilities cSharpUtilities)
34+
[NotNull] ICSharpUtilities cSharpUtilities)
3535
{
3636
Check.NotNull(cSharpUtilities, nameof(cSharpUtilities));
3737

@@ -42,7 +42,7 @@ public CSharpEntityTypeGenerator(
4242
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
4343
/// directly from your code. This API may change or be removed in future releases.
4444
/// </summary>
45-
public virtual string WriteCode([NotNull] IEntityType entityType, [NotNull] string @namespace, bool useDataAnnotations)
45+
public virtual string WriteCode(IEntityType entityType, string @namespace, bool useDataAnnotations)
4646
{
4747
Check.NotNull(entityType, nameof(entityType));
4848
Check.NotNull(@namespace, nameof(@namespace));

src/EFCore.Design/Scaffolding/Internal/CSharpNamer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
1515
public class CSharpNamer<T>
1616
{
1717
private readonly Func<T, string> _nameGetter;
18-
private readonly CSharpUtilities _cSharpUtilities;
18+
private readonly ICSharpUtilities _cSharpUtilities;
1919

2020
/// <summary>
2121
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
@@ -27,12 +27,13 @@ public class CSharpNamer<T>
2727
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
2828
/// directly from your code. This API may change or be removed in future releases.
2929
/// </summary>
30-
public CSharpNamer([NotNull] Func<T, string> nameGetter)
30+
public CSharpNamer([NotNull] Func<T, string> nameGetter, [NotNull] ICSharpUtilities cSharpUtilities)
3131
{
3232
Check.NotNull(nameGetter, nameof(nameGetter));
33+
Check.NotNull(cSharpUtilities, nameof(cSharpUtilities));
3334

3435
_nameGetter = nameGetter;
35-
_cSharpUtilities = new CSharpUtilities();
36+
_cSharpUtilities = cSharpUtilities;
3637
}
3738

3839
/// <summary>

src/EFCore.Design/Scaffolding/Internal/CSharpScaffoldingGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ public class CSharpScaffoldingGenerator : ScaffoldingCodeGenerator
2020
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
2121
/// directly from your code. This API may change or be removed in future releases.
2222
/// </summary>
23-
public virtual CSharpDbContextGenerator CSharpDbContextGenerator { get; }
23+
public virtual ICSharpDbContextGenerator CSharpDbContextGenerator { get; }
2424

2525
/// <summary>
2626
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
2727
/// directly from your code. This API may change or be removed in future releases.
2828
/// </summary>
29-
public virtual CSharpEntityTypeGenerator CSharpEntityTypeGenerator { get; }
29+
public virtual ICSharpEntityTypeGenerator CSharpEntityTypeGenerator { get; }
3030

3131
/// <summary>
3232
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
3333
/// directly from your code. This API may change or be removed in future releases.
3434
/// </summary>
3535
public CSharpScaffoldingGenerator(
3636
[NotNull] IFileService fileService,
37-
[NotNull] CSharpDbContextGenerator cSharpDbContextGenerator,
38-
[NotNull] CSharpEntityTypeGenerator cSharpEntityTypeGenerator)
37+
[NotNull] ICSharpDbContextGenerator cSharpDbContextGenerator,
38+
[NotNull] ICSharpEntityTypeGenerator cSharpEntityTypeGenerator)
3939
: base(fileService)
4040
{
4141
Check.NotNull(cSharpDbContextGenerator, nameof(cSharpDbContextGenerator));

src/EFCore.Design/Scaffolding/Internal/CSharpUniqueNamer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class CSharpUniqueNamer<T> : CSharpNamer<T>
1919
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
2020
/// directly from your code. This API may change or be removed in future releases.
2121
/// </summary>
22-
public CSharpUniqueNamer([NotNull] Func<T, string> nameGetter)
23-
: this(nameGetter, null)
22+
public CSharpUniqueNamer([NotNull] Func<T, string> nameGetter, [NotNull] ICSharpUtilities cSharpUtilities)
23+
: this(nameGetter, null, cSharpUtilities)
2424
{
2525
}
2626

@@ -29,8 +29,9 @@ public CSharpUniqueNamer([NotNull] Func<T, string> nameGetter)
2929
/// directly from your code. This API may change or be removed in future releases.
3030
/// </summary>
3131
public CSharpUniqueNamer([NotNull] Func<T, string> nameGetter,
32-
[CanBeNull] IEnumerable<string> usedNames)
33-
: base(nameGetter)
32+
[CanBeNull] IEnumerable<string> usedNames,
33+
[NotNull] ICSharpUtilities cSharpUtilities)
34+
: base(nameGetter, cSharpUtilities)
3435
{
3536
if (usedNames != null)
3637
{

src/EFCore.Design/Scaffolding/Internal/CSharpUtilities.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
1616
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
1717
/// directly from your code. This API may change or be removed in future releases.
1818
/// </summary>
19-
public class CSharpUtilities
19+
public class CSharpUtilities : ICSharpUtilities
2020
{
2121
private static readonly HashSet<string> _cSharpKeywords = new HashSet<string>
2222
{
@@ -108,13 +108,7 @@ private static readonly Regex _invalidCharsRegex
108108
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
109109
/// directly from your code. This API may change or be removed in future releases.
110110
/// </summary>
111-
public static CSharpUtilities Instance { get; } = new CSharpUtilities();
112-
113-
/// <summary>
114-
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
115-
/// directly from your code. This API may change or be removed in future releases.
116-
/// </summary>
117-
public virtual string DelimitString([NotNull] string value)
111+
public virtual string DelimitString(string value)
118112
{
119113
Check.NotNull(value, nameof(value));
120114

@@ -127,7 +121,7 @@ public virtual string DelimitString([NotNull] string value)
127121
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
128122
/// directly from your code. This API may change or be removed in future releases.
129123
/// </summary>
130-
public virtual string EscapeString([NotNull] string str)
124+
public virtual string EscapeString(string str)
131125
{
132126
Check.NotNull(str, nameof(str));
133127

@@ -138,7 +132,7 @@ public virtual string EscapeString([NotNull] string str)
138132
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
139133
/// directly from your code. This API may change or be removed in future releases.
140134
/// </summary>
141-
public virtual string EscapeVerbatimString([NotNull] string str)
135+
public virtual string EscapeVerbatimString(string str)
142136
{
143137
Check.NotEmpty(str, nameof(str));
144138

@@ -149,7 +143,7 @@ public virtual string EscapeVerbatimString([NotNull] string str)
149143
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
150144
/// directly from your code. This API may change or be removed in future releases.
151145
/// </summary>
152-
public virtual string GenerateLiteral([NotNull] byte[] value)
146+
public virtual string GenerateLiteral(byte[] value)
153147
{
154148
Check.NotNull(value, nameof(value));
155149

@@ -232,7 +226,7 @@ public virtual string GenerateLiteral(Guid value)
232226
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
233227
/// directly from your code. This API may change or be removed in future releases.
234228
/// </summary>
235-
public virtual string GenerateLiteral([NotNull] string value)
229+
public virtual string GenerateLiteral(string value)
236230
{
237231
Check.NotNull(value, nameof(value));
238232

@@ -243,7 +237,7 @@ public virtual string GenerateLiteral([NotNull] string value)
243237
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
244238
/// directly from your code. This API may change or be removed in future releases.
245239
/// </summary>
246-
public virtual string GenerateVerbatimStringLiteral([NotNull] string value)
240+
public virtual string GenerateVerbatimStringLiteral(string value)
247241
{
248242
Check.NotNull(value, nameof(value));
249243

@@ -254,7 +248,7 @@ public virtual string GenerateVerbatimStringLiteral([NotNull] string value)
254248
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
255249
/// directly from your code. This API may change or be removed in future releases.
256250
/// </summary>
257-
public virtual string GenerateLiteral([NotNull] object value)
251+
public virtual string GenerateLiteral(object value)
258252
{
259253
Check.NotNull(value, nameof(value));
260254

@@ -270,24 +264,24 @@ public virtual string GenerateLiteral([NotNull] object value)
270264
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
271265
/// directly from your code. This API may change or be removed in future releases.
272266
/// </summary>
273-
public virtual bool IsCSharpKeyword([NotNull] string identifier)
267+
public virtual bool IsCSharpKeyword(string identifier)
274268
=> _cSharpKeywords.Contains(identifier);
275269

276270
/// <summary>
277271
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
278272
/// directly from your code. This API may change or be removed in future releases.
279273
/// </summary>
280274
public virtual string GenerateCSharpIdentifier(
281-
[NotNull] string identifier, [CanBeNull] ICollection<string> existingIdentifiers)
275+
string identifier, [CanBeNull] ICollection<string> existingIdentifiers)
282276
=> GenerateCSharpIdentifier(identifier, existingIdentifiers, Uniquifier);
283277

284278
/// <summary>
285279
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
286280
/// directly from your code. This API may change or be removed in future releases.
287281
/// </summary>
288282
public virtual string GenerateCSharpIdentifier(
289-
[NotNull] string identifier, [CanBeNull] ICollection<string> existingIdentifiers,
290-
[NotNull] Func<string, ICollection<string>, string> uniquifier)
283+
string identifier, [CanBeNull] ICollection<string> existingIdentifiers,
284+
Func<string, ICollection<string>, string> uniquifier)
291285
{
292286
Check.NotNull(identifier, nameof(identifier));
293287
Check.NotNull(uniquifier, nameof(uniquifier));
@@ -321,7 +315,7 @@ public virtual string GenerateCSharpIdentifier(
321315
/// directly from your code. This API may change or be removed in future releases.
322316
/// </summary>
323317
public virtual string Uniquifier(
324-
[NotNull] string proposedIdentifier, [CanBeNull] ICollection<string> existingIdentifiers)
318+
string proposedIdentifier, [CanBeNull] ICollection<string> existingIdentifiers)
325319
{
326320
Check.NotEmpty(proposedIdentifier, nameof(proposedIdentifier));
327321

@@ -364,7 +358,7 @@ public virtual string Uniquifier(
364358
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
365359
/// directly from your code. This API may change or be removed in future releases.
366360
/// </summary>
367-
public virtual string GetTypeName([NotNull] Type type)
361+
public virtual string GetTypeName(Type type)
368362
{
369363
Check.NotNull(type, nameof(type));
370364

src/EFCore.Design/Scaffolding/Internal/CandidateNamingService.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using System.Text;
8-
using JetBrains.Annotations;
98
using Microsoft.EntityFrameworkCore.Metadata;
109
using Microsoft.EntityFrameworkCore.Metadata.Internal;
1110
using Microsoft.EntityFrameworkCore.Utilities;
@@ -16,13 +15,13 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
1615
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
1716
/// directly from your code. This API may change or be removed in future releases.
1817
/// </summary>
19-
public class CandidateNamingService
18+
public class CandidateNamingService : ICandidateNamingService
2019
{
2120
/// <summary>
2221
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
2322
/// directly from your code. This API may change or be removed in future releases.
2423
/// </summary>
25-
public virtual string GenerateCandidateIdentifier([NotNull] string originalIdentifier)
24+
public virtual string GenerateCandidateIdentifier(string originalIdentifier)
2625
{
2726
Check.NotEmpty(originalIdentifier, nameof(originalIdentifier));
2827

@@ -59,7 +58,7 @@ public virtual string GenerateCandidateIdentifier([NotNull] string originalIdent
5958
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
6059
/// directly from your code. This API may change or be removed in future releases.
6160
/// </summary>
62-
public virtual string GetDependentEndCandidateNavigationPropertyName([NotNull] IForeignKey foreignKey)
61+
public virtual string GetDependentEndCandidateNavigationPropertyName(IForeignKey foreignKey)
6362
{
6463
Check.NotNull(foreignKey, nameof(foreignKey));
6564

@@ -78,8 +77,8 @@ public virtual string GetDependentEndCandidateNavigationPropertyName([NotNull] I
7877
/// directly from your code. This API may change or be removed in future releases.
7978
/// </summary>
8079
public virtual string GetPrincipalEndCandidateNavigationPropertyName(
81-
[NotNull] IForeignKey foreignKey,
82-
[NotNull] string dependentEndNavigationPropertyName)
80+
IForeignKey foreignKey,
81+
string dependentEndNavigationPropertyName)
8382
{
8483
Check.NotNull(foreignKey, nameof(foreignKey));
8584
Check.NotEmpty(dependentEndNavigationPropertyName, nameof(dependentEndNavigationPropertyName));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using JetBrains.Annotations;
5+
using Microsoft.EntityFrameworkCore.Metadata;
6+
7+
namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
8+
{
9+
public interface ICSharpDbContextGenerator
10+
{
11+
string WriteCode(
12+
[NotNull] IModel model,
13+
[NotNull] string @namespace,
14+
[NotNull] string contextName,
15+
[NotNull] string connectionString,
16+
bool useDataAnnotations);
17+
}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using JetBrains.Annotations;
5+
using Microsoft.EntityFrameworkCore.Metadata;
6+
7+
namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
8+
{
9+
public interface ICSharpEntityTypeGenerator
10+
{
11+
string WriteCode([NotNull] IEntityType entityType, [NotNull] string @namespace, bool useDataAnnotations);
12+
}
13+
}

0 commit comments

Comments
 (0)