Skip to content

Commit 7a50ed8

Browse files
committed
license, comments, refactor
1 parent d834ab9 commit 7a50ed8

34 files changed

+379
-186
lines changed

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2022 AutSoft
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

src/.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ csharp_style_expression_bodied_indexers = true:suggestion
6868
csharp_style_expression_bodied_accessors = true:suggestion
6969
csharp_style_expression_bodied_lambdas = true:suggestion
7070
csharp_style_expression_bodied_local_functions = true:suggestion
71+
csharp_style_throw_expression = true:warning
72+
csharp_style_prefer_null_check_over_type_check = true:warning
73+
csharp_prefer_simple_default_expression = true:warning
7174

7275
##########################################
7376
# File Extension Settings
@@ -577,3 +580,6 @@ dotnet_diagnostic.IDE0022.severity = suggestion
577580
dotnet_diagnostic.CA1848.severity = suggestion
578581
tab_width = 4
579582
end_of_line = crlf
583+
584+
# SA1615: Element return value should be documented
585+
dotnet_diagnostic.SA1615.severity = suggestion

src/AutSoft.DbScaffolding.Identity/IdentityScaffoldingOptions.cs renamed to src/AutSoft.DbScaffolding.Identity/Configuration/IdentityScaffoldingOptions.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
using AutSoft.DbScaffolding.Configuration;
2+
13
using Microsoft.AspNetCore.Identity;
24

35
using System;
46
using System.Collections.Generic;
57

6-
namespace AutSoft.DbScaffolding.Identity;
8+
namespace AutSoft.DbScaffolding.Identity.Configuration;
79

10+
/// <summary>
11+
/// Configuration of scaffolding code first model with ASP.NET Core Identity
12+
/// </summary>
813
public class IdentityScaffoldingOptions
914
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="IdentityScaffoldingOptions"/> class.
17+
/// </summary>
1018
public IdentityScaffoldingOptions()
1119
{
1220
UserTableName = "User";
@@ -18,14 +26,44 @@ public IdentityScaffoldingOptions()
1826
UserTokenTableName = "UserToken";
1927
}
2028

29+
/// <summary>
30+
/// Gets or sets name of identity user table
31+
/// </summary>
2132
public string UserTableName { get; set; }
33+
34+
/// <summary>
35+
/// Gets or sets name of identity role table
36+
/// </summary>
2237
public string RoleTableName { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets name of identity role-claim cross reference table
41+
/// </summary>
2342
public string RoleClaimTableName { get; set; }
43+
44+
/// <summary>
45+
/// Gets or sets name of identity user-claim cross reference table
46+
/// </summary>
2447
public string UserClaimTableName { get; set; }
48+
49+
/// <summary>
50+
/// Gets or sets name of identity user login table
51+
/// </summary>
2552
public string UserLoginTableName { get; set; }
53+
54+
/// <summary>
55+
/// Gets or sets name of identity user-role cross reference table
56+
/// </summary>
2657
public string UserRoleTableName { get; set; }
58+
59+
/// <summary>
60+
/// Gets or sets name of identity user token table
61+
/// </summary>
2762
public string UserTokenTableName { get; set; }
2863

64+
/// <summary>
65+
/// Gets or sets base scaffolding configuration
66+
/// </summary>
2967
public DbScaffoldingOptions DbScaffoldingOptions { get; set; } = new DbScaffoldingOptions();
3068

3169
internal Dictionary<string, Type> CreateIdentityTableNameLookup(Type keyType)

src/AutSoft.DbScaffolding.Identity/Extensions/IModelExtensions.cs renamed to src/AutSoft.DbScaffolding.Identity/Extensions/ModelExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using Microsoft.EntityFrameworkCore.Metadata;
1+
using Microsoft.EntityFrameworkCore.Metadata;
22

33
using System;
44
using System.Linq;
55

66
namespace AutSoft.DbScaffolding.Identity.Extensions;
77

8-
public static class IModelExtensions
8+
internal static class ModelExtensions
99
{
1010
public static Type FindIdentityKeyType(this IModel model, string userTableName)
1111
{

src/AutSoft.DbScaffolding.Identity/Extensions/ServiceCollectionExtensions.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/AutSoft.DbScaffolding.Identity/IdentityCSharpDbContextGenerator.cs renamed to src/AutSoft.DbScaffolding.Identity/Generators/IdentityCSharpDbContextGenerator.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using AutSoft.DbScaffolding.Configuration;
2+
using AutSoft.DbScaffolding.Generators;
3+
using AutSoft.DbScaffolding.Identity.Configuration;
14
using AutSoft.DbScaffolding.Identity.Extensions;
25

36
using EntityFrameworkCore.Scaffolding.Handlebars;
@@ -11,10 +14,10 @@
1114
using System.Collections.Generic;
1215
using System.Linq;
1316

14-
namespace AutSoft.DbScaffolding.Identity;
17+
namespace AutSoft.DbScaffolding.Identity.Generators;
1518

1619
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "We do some low level stuff, so we take the risks.")]
17-
public class IdentityCSharpDbContextGenerator : CSharpDbContextGenerator
20+
internal class IdentityCSharpDbContextGenerator : CSharpDbContextGenerator
1821
{
1922
private readonly IOptions<HandlebarsScaffoldingOptions> _options;
2023
private readonly IOptions<IdentityScaffoldingOptions> _identityOptions;

src/AutSoft.DbScaffolding.Identity/IdentityCSharpEntityTypeGenerator.cs renamed to src/AutSoft.DbScaffolding.Identity/Generators/IdentityCSharpEntityTypeGenerator.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using AutSoft.DbScaffolding.Identity.Extensions;
1+
using AutSoft.DbScaffolding.Configuration;
2+
using AutSoft.DbScaffolding.Generators;
3+
using AutSoft.DbScaffolding.Helpers;
4+
using AutSoft.DbScaffolding.Identity.Configuration;
5+
using AutSoft.DbScaffolding.Identity.Extensions;
26

37
using EntityFrameworkCore.Scaffolding.Handlebars;
48

@@ -11,9 +15,9 @@
1115
using System.Collections.Generic;
1216
using System.Linq;
1317

14-
namespace AutSoft.DbScaffolding.Identity;
18+
namespace AutSoft.DbScaffolding.Identity.Generators;
1519

16-
public class IdentityCSharpEntityTypeGenerator : CSharpEntityTypeGenerator
20+
internal class IdentityCSharpEntityTypeGenerator : CSharpEntityTypeGenerator
1721
{
1822
private readonly IOptions<IdentityScaffoldingOptions> _identityOptions;
1923

@@ -35,9 +39,7 @@ protected override void GenerateClass(IEntityType entityType)
3539
Check.NotNull(entityType, nameof(entityType));
3640

3741
if (UseDataAnnotations)
38-
{
3942
GenerateEntityTypeDataAnnotations(entityType);
40-
}
4143

4244
var identityKeyType = entityType.Model.FindIdentityKeyType(_identityOptions.Value.UserTableName);
4345
var lookup = _identityOptions.Value.CreateIdentityTableNameLookup(identityKeyType);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using AutSoft.DbScaffolding.Identity.Configuration;
2+
using AutSoft.DbScaffolding.Identity.Generators;
3+
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
using System;
7+
8+
namespace AutSoft.DbScaffolding.Identity;
9+
10+
/// <summary>
11+
/// Register all relevant services into dependency injection container
12+
/// </summary>
13+
public static class ServiceCollectionExtensions
14+
{
15+
/// <summary>
16+
/// Register all relevant services into dependency injection container
17+
/// </summary>
18+
public static IServiceCollection AddIdentityScaffolding(this IServiceCollection services, Action<IdentityScaffoldingOptions> identityConfigureOptions)
19+
{
20+
services.AddDatabaseScaffoldingCore<IdentityCSharpEntityTypeGenerator, IdentityCSharpDbContextGenerator>(
21+
options => identityConfigureOptions(new IdentityScaffoldingOptions
22+
{
23+
DbScaffoldingOptions = options,
24+
}));
25+
26+
services.Configure(identityConfigureOptions);
27+
28+
return services;
29+
}
30+
}

src/AutSoft.DbScaffolding/AutSoft.DbScaffolding.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>

src/AutSoft.DbScaffolding/DbColumn.cs renamed to src/AutSoft.DbScaffolding/Configuration/DbColumn.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
1-
namespace AutSoft.DbScaffolding;
1+
namespace AutSoft.DbScaffolding.Configuration;
22

3+
/// <summary>
4+
/// Data of a database column
5+
/// </summary>
36
public class DbColumn
47
{
8+
/// <summary>
9+
/// Initializes a new instance of the <see cref="DbColumn"/> class.
10+
/// </summary>
11+
/// <param name="schemaName">Table's containing schema</param>
12+
/// <param name="tableName">Table's name</param>
13+
/// <param name="columnName">Column's name</param>
514
public DbColumn(string schemaName, string tableName, string columnName)
615
{
716
SchemaName = schemaName;
817
TableName = tableName;
918
ColumnName = columnName;
1019
}
1120

21+
/// <summary>
22+
/// Gets or sets table's containing schema
23+
/// </summary>
1224
public string SchemaName { get; set; }
25+
26+
/// <summary>
27+
/// Gets or sets table's name
28+
/// </summary>
1329
public string TableName { get; set; }
30+
31+
/// <summary>
32+
/// Gets or sets column's name
33+
/// </summary>
1434
public string ColumnName { get; set; }
1535

36+
/// <inheritdoc/>
1637
public override bool Equals(object obj)
1738
{
1839
if (obj is DbColumn dbColumn)
@@ -25,6 +46,7 @@ public override bool Equals(object obj)
2546
return false;
2647
}
2748

49+
/// <inheritdoc/>
2850
public override int GetHashCode()
2951
{
3052
return SchemaName.GetHashCode() ^ TableName.GetHashCode() ^ ColumnName.GetHashCode();

0 commit comments

Comments
 (0)