Skip to content

Commit 2c8fdf5

Browse files
dotnet 8
1 parent 231753f commit 2c8fdf5

File tree

42 files changed

+457
-338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+457
-338
lines changed

nuget.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net7.0</TargetFramework>
3+
<TargetFramework>net8.0</TargetFramework>
44
<IncludeContentInPack>true</IncludeContentInPack>
55
<IncludeBuildOutput>false</IncludeBuildOutput>
66
<ContentTargetFolders>content</ContentTargetFolders>
@@ -18,15 +18,15 @@
1818

1919
<PropertyGroup>
2020
<PackageType>Template</PackageType>
21-
<Version>7.0.3</Version>
21+
<Version>8.0.0</Version>
2222
<PackageId>AspNetCoreTemplate</PackageId>
2323
<Title>ASP.NET Core Template</Title>
2424
<Company>Nikolay.IT</Company>
2525
<Authors>Nikolay.IT</Authors>
2626
<Copyright>Nikolay.IT © 2017-2023</Copyright>
27-
<Description>A ready-to-use template for ASP.NET Core 6 with repositories, services, models mapping, DI and StyleCop warnings fixed.</Description>
27+
<Description>A ready-to-use template for ASP.NET Core 8 with repositories, services, models mapping, DI and StyleCop warnings fixed.</Description>
2828
<PackageTags>c#;asp.net;core;template;web</PackageTags>
29-
<PackageCopyright>Nikolay.IT © 2017-2023</PackageCopyright>
29+
<PackageCopyright>Nikolay.IT © 2017-2025</PackageCopyright>
3030
<PackageProjectUrl>https://github.com/NikolayIT/ASP.NET-Core-Template</PackageProjectUrl>
3131
<PackageLicenseExpression>MIT</PackageLicenseExpression>
3232
<RepositoryType>git</RepositoryType>

src/AspNetCoreTemplate.Common/AspNetCoreTemplate.Common.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
</PropertyGroup>
77

src/Data/AspNetCoreTemplate.Data.Common/AspNetCoreTemplate.Data.Common.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
</PropertyGroup>
77

src/Data/AspNetCoreTemplate.Data.Models/ApplicationRole.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ public ApplicationRole()
1616

1717
public ApplicationRole(string name)
1818
: base(name)
19-
{
20-
this.Id = Guid.NewGuid().ToString();
21-
}
19+
=> this.Id = Guid.NewGuid().ToString();
2220

2321
public DateTime CreatedOn { get; set; }
2422

src/Data/AspNetCoreTemplate.Data.Models/AspNetCoreTemplate.Data.Models.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
</PropertyGroup>
77

@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.3" />
16+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.15" />
1717
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all">
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1919
</PackageReference>

src/Data/AspNetCoreTemplate.Data/ApplicationDbContext.cs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@
1212
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
1313
using Microsoft.EntityFrameworkCore;
1414

15-
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
15+
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
16+
: IdentityDbContext<ApplicationUser, ApplicationRole, string>(options)
1617
{
1718
private static readonly MethodInfo SetIsDeletedQueryFilterMethod =
1819
typeof(ApplicationDbContext).GetMethod(
1920
nameof(SetIsDeletedQueryFilter),
2021
BindingFlags.NonPublic | BindingFlags.Static);
2122

22-
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
23-
: base(options)
24-
{
25-
}
26-
2723
public DbSet<Setting> Settings { get; set; }
2824

2925
public override int SaveChanges() => this.SaveChanges(true);
@@ -76,34 +72,30 @@ protected override void OnModelCreating(ModelBuilder builder)
7672

7773
private static void SetIsDeletedQueryFilter<T>(ModelBuilder builder)
7874
where T : class, IDeletableEntity
79-
{
80-
builder.Entity<T>().HasQueryFilter(e => !e.IsDeleted);
81-
}
75+
=> builder.Entity<T>().HasQueryFilter(e => !e.IsDeleted);
8276

8377
// Applies configurations
8478
private void ConfigureUserIdentityRelations(ModelBuilder builder)
8579
=> builder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
8680

8781
private void ApplyAuditInfoRules()
88-
{
89-
var changedEntries = this.ChangeTracker
82+
=> this.ChangeTracker
9083
.Entries()
9184
.Where(e =>
9285
e.Entity is IAuditInfo &&
93-
(e.State == EntityState.Added || e.State == EntityState.Modified));
94-
95-
foreach (var entry in changedEntries)
96-
{
97-
var entity = (IAuditInfo)entry.Entity;
98-
if (entry.State == EntityState.Added && entity.CreatedOn == default)
99-
{
100-
entity.CreatedOn = DateTime.UtcNow;
101-
}
102-
else
86+
(e.State == EntityState.Added || e.State == EntityState.Modified))
87+
.ToList()
88+
.ForEach(entry =>
10389
{
104-
entity.ModifiedOn = DateTime.UtcNow;
105-
}
106-
}
107-
}
90+
var entity = (IAuditInfo)entry.Entity;
91+
if (entry.State == EntityState.Added && entity.CreatedOn == default)
92+
{
93+
entity.CreatedOn = DateTime.UtcNow;
94+
}
95+
else
96+
{
97+
entity.ModifiedOn = DateTime.UtcNow;
98+
}
99+
});
108100
}
109101
}

src/Data/AspNetCoreTemplate.Data/AspNetCoreTemplate.Data.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
66
<LangVersion>latest</LangVersion>
77
</PropertyGroup>
@@ -22,17 +22,17 @@
2222
</ItemGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.3" />
26-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
25+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.15" />
26+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.15">
2727
<PrivateAssets>all</PrivateAssets>
2828
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2929
</PackageReference>
30-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
31-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
30+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.15" />
31+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.15">
3232
<PrivateAssets>all</PrivateAssets>
3333
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
3434
</PackageReference>
35-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
35+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
3636
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all">
3737
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
3838
</PackageReference>

src/Data/AspNetCoreTemplate.Data/DbQueryRunner.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,12 @@
77

88
using Microsoft.EntityFrameworkCore;
99

10-
public class DbQueryRunner : IDbQueryRunner
10+
public class DbQueryRunner(ApplicationDbContext context) : IDbQueryRunner
1111
{
12-
public DbQueryRunner(ApplicationDbContext context)
13-
{
14-
this.Context = context ?? throw new ArgumentNullException(nameof(context));
15-
}
16-
17-
public ApplicationDbContext Context { get; set; }
12+
public ApplicationDbContext Context { get; set; } = context ?? throw new ArgumentNullException(nameof(context));
1813

1914
public Task RunQueryAsync(string query, params object[] parameters)
20-
{
21-
return this.Context.Database.ExecuteSqlRawAsync(query, parameters);
22-
}
15+
=> this.Context.Database.ExecuteSqlRawAsync(query, parameters);
2316

2417
public void Dispose()
2518
{

src/Data/AspNetCoreTemplate.Data/EntityIndexesConfiguration.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
internal static class EntityIndexesConfiguration
1010
{
1111
public static void Configure(ModelBuilder modelBuilder)
12-
{
13-
// IDeletableEntity.IsDeleted index
14-
var deletableEntityTypes = modelBuilder.Model
12+
=> modelBuilder.Model
1513
.GetEntityTypes()
16-
.Where(et => et.ClrType != null && typeof(IDeletableEntity).IsAssignableFrom(et.ClrType));
17-
foreach (var deletableEntityType in deletableEntityTypes)
18-
{
19-
modelBuilder.Entity(deletableEntityType.ClrType).HasIndex(nameof(IDeletableEntity.IsDeleted));
20-
}
21-
}
14+
.Where(et => et.ClrType != null && typeof(IDeletableEntity).IsAssignableFrom(et.ClrType))
15+
.ToList()
16+
.ForEach(deletableEntityType =>
17+
modelBuilder
18+
.Entity(deletableEntityType.ClrType)
19+
.HasIndex(nameof(IDeletableEntity.IsDeleted)));
2220
}
2321
}

src/Data/AspNetCoreTemplate.Data/Migrations/ApplicationDbContextModelSnapshot.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
// <auto-generated />
2-
using System;
3-
using AspNetCoreTemplate.Data;
4-
using Microsoft.EntityFrameworkCore;
5-
using Microsoft.EntityFrameworkCore.Infrastructure;
6-
using Microsoft.EntityFrameworkCore.Metadata;
7-
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8-
9-
#nullable disable
1+
#nullable disable
102

113
namespace AspNetCoreTemplate.Data.Migrations
124
{
5+
using System;
6+
7+
using Microsoft.EntityFrameworkCore;
8+
using Microsoft.EntityFrameworkCore.Infrastructure;
9+
1310
[DbContext(typeof(ApplicationDbContext))]
14-
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
11+
internal partial class ApplicationDbContextModelSnapshot : ModelSnapshot
1512
{
1613
protected override void BuildModel(ModelBuilder modelBuilder)
1714
{

src/Data/AspNetCoreTemplate.Data/Repositories/EfDeletableEntityRepository.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88

99
using Microsoft.EntityFrameworkCore;
1010

11-
public class EfDeletableEntityRepository<TEntity> : EfRepository<TEntity>, IDeletableEntityRepository<TEntity>
12-
where TEntity : class, IDeletableEntity
11+
public class EfDeletableEntityRepository<TEntity>(ApplicationDbContext context)
12+
: EfRepository<TEntity>(context), IDeletableEntityRepository<TEntity>
13+
where TEntity : class, IDeletableEntity
1314
{
14-
public EfDeletableEntityRepository(ApplicationDbContext context)
15-
: base(context)
16-
{
17-
}
18-
1915
public override IQueryable<TEntity> All() => base.All().Where(x => !x.IsDeleted);
2016

2117
public override IQueryable<TEntity> AllAsNoTracking() => base.AllAsNoTracking().Where(x => !x.IsDeleted);

src/Data/AspNetCoreTemplate.Data/Seeding/ApplicationDbContextSeeder.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,16 @@ public class ApplicationDbContextSeeder : ISeeder
1111
{
1212
public async Task SeedAsync(ApplicationDbContext dbContext, IServiceProvider serviceProvider)
1313
{
14-
if (dbContext == null)
15-
{
16-
throw new ArgumentNullException(nameof(dbContext));
17-
}
18-
19-
if (serviceProvider == null)
20-
{
21-
throw new ArgumentNullException(nameof(serviceProvider));
22-
}
14+
ArgumentNullException.ThrowIfNull(dbContext);
15+
ArgumentNullException.ThrowIfNull(serviceProvider);
2316

2417
var logger = serviceProvider.GetService<ILoggerFactory>().CreateLogger(typeof(ApplicationDbContextSeeder));
2518

2619
var seeders = new List<ISeeder>
27-
{
28-
new RolesSeeder(),
29-
new SettingsSeeder(),
30-
};
20+
{
21+
new RolesSeeder(),
22+
new SettingsSeeder(),
23+
};
3124

3225
foreach (var seeder in seeders)
3326
{

src/Services/AspNetCoreTemplate.Services.Data/AspNetCoreTemplate.Services.Data.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
</PropertyGroup>
77

@@ -22,6 +22,7 @@
2222
<ProjectReference Include="..\..\Data\AspNetCoreTemplate.Data.Common\AspNetCoreTemplate.Data.Common.csproj" />
2323
<ProjectReference Include="..\..\Data\AspNetCoreTemplate.Data.Models\AspNetCoreTemplate.Data.Models.csproj" />
2424
<ProjectReference Include="..\AspNetCoreTemplate.Services.Mapping\AspNetCoreTemplate.Services.Mapping.csproj" />
25+
<ProjectReference Include="..\AspNetCoreTemplate.Services\AspNetCoreTemplate.Services.csproj" />
2526
</ItemGroup>
2627

2728
</Project>

src/Services/AspNetCoreTemplate.Services.Data/ISettingsService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
{
33
using System.Collections.Generic;
44

5-
public interface ISettingsService
5+
using AspNetCoreTemplate.Services.ServiceLifetimes;
6+
7+
public interface ISettingsService : ITransientService
68
{
79
int GetCount();
810

src/Services/AspNetCoreTemplate.Services.Data/SettingsService.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,12 @@
77
using AspNetCoreTemplate.Data.Models;
88
using AspNetCoreTemplate.Services.Mapping;
99

10-
public class SettingsService : ISettingsService
10+
public class SettingsService(IDeletableEntityRepository<Setting> settingsRepository) : ISettingsService
1111
{
12-
private readonly IDeletableEntityRepository<Setting> settingsRepository;
12+
private readonly IDeletableEntityRepository<Setting> settingsRepository = settingsRepository;
1313

14-
public SettingsService(IDeletableEntityRepository<Setting> settingsRepository)
15-
{
16-
this.settingsRepository = settingsRepository;
17-
}
14+
public int GetCount() => this.settingsRepository.AllAsNoTracking().Count();
1815

19-
public int GetCount()
20-
{
21-
return this.settingsRepository.AllAsNoTracking().Count();
22-
}
23-
24-
public IEnumerable<T> GetAll<T>()
25-
{
26-
return this.settingsRepository.All().To<T>().ToList();
27-
}
16+
public IEnumerable<T> GetAll<T>() => this.settingsRepository.All().To<T>().ToList();
2817
}
2918
}

src/Services/AspNetCoreTemplate.Services.Mapping/AspNetCoreTemplate.Services.Mapping.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
</PropertyGroup>
77

@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="AutoMapper" Version="12.0.1" />
16+
<PackageReference Include="AutoMapper" Version="14.0.0" />
1717
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all">
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1919
</PackageReference>

0 commit comments

Comments
 (0)