Skip to content

Commit ecd190b

Browse files
committed
Convert to file scoped namespace
1 parent 9435c7c commit ecd190b

File tree

220 files changed

+6787
-7013
lines changed

Some content is hidden

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

220 files changed

+6787
-7013
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ dotnet_naming_style.instance_field_style.required_prefix = _
134134
csharp_indent_labels = one_less_than_current
135135
csharp_using_directive_placement = outside_namespace:silent
136136
csharp_prefer_simple_using_statement = true:suggestion
137-
csharp_style_namespace_declarations = block_scoped:silent
137+
csharp_style_namespace_declarations = file_scoped:silent
138138
csharp_style_prefer_method_group_conversion = true:silent
139139
csharp_style_prefer_top_level_statements = true:silent
140140
csharp_style_prefer_primary_constructors = true:suggestion
Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,69 @@
11
using Microsoft.EntityFrameworkCore;
22
using Microsoft.EntityFrameworkCore.Infrastructure;
33

4-
namespace EntityFrameworkCore.Triggered.Benchmarks
4+
namespace EntityFrameworkCore.Triggered.Benchmarks;
5+
6+
public class Student
57
{
6-
public class Student
7-
{
8-
public Guid Id { get; set; }
8+
public Guid Id { get; set; }
99

10-
public string DisplayName { get; set; }
10+
public string DisplayName { get; set; }
1111

12-
public DateTimeOffset RegistrationDate { get; set; }
13-
}
12+
public DateTimeOffset RegistrationDate { get; set; }
13+
}
1414

15-
public class Course
16-
{
17-
public Guid Id { get; set; }
15+
public class Course
16+
{
17+
public Guid Id { get; set; }
1818

19-
public string DisplayName { get; set; }
19+
public string DisplayName { get; set; }
2020

21-
public bool IsMandatory { get; set; }
21+
public bool IsMandatory { get; set; }
2222

23-
}
23+
}
2424

25-
public class StudentCourse
26-
{
27-
public Guid StudentId { get; set; }
25+
public class StudentCourse
26+
{
27+
public Guid StudentId { get; set; }
2828

29-
public Guid CourseId { get; set; }
29+
public Guid CourseId { get; set; }
3030

31-
public Student Student { get; set; }
31+
public Student Student { get; set; }
3232

33-
public Course Course { get; set; }
34-
}
33+
public Course Course { get; set; }
34+
}
3535

36-
public interface IApplicationContextContract : IDisposable
37-
{
38-
DatabaseFacade Database { get; }
36+
public interface IApplicationContextContract : IDisposable
37+
{
38+
DatabaseFacade Database { get; }
3939

40-
int SaveChanges();
40+
int SaveChanges();
4141

42-
DbSet<Student> Students { get; set; }
42+
DbSet<Student> Students { get; set; }
4343

44-
DbSet<Course> Courses { get; set; }
44+
DbSet<Course> Courses { get; set; }
4545

46-
DbSet<StudentCourse> StudentCourses { get; set; }
47-
}
46+
DbSet<StudentCourse> StudentCourses { get; set; }
47+
}
4848

49-
public class ApplicationContext(DbContextOptions<ApplicationContext> options) : DbContext(options), IApplicationContextContract
50-
{
51-
protected override void OnModelCreating(ModelBuilder modelBuilder) => modelBuilder.Entity<StudentCourse>().HasKey(x => new { x.StudentId, x.CourseId });
49+
public class ApplicationContext(DbContextOptions<ApplicationContext> options) : DbContext(options), IApplicationContextContract
50+
{
51+
protected override void OnModelCreating(ModelBuilder modelBuilder) => modelBuilder.Entity<StudentCourse>().HasKey(x => new { x.StudentId, x.CourseId });
5252

53-
public DbSet<Student> Students { get; set; }
53+
public DbSet<Student> Students { get; set; }
5454

55-
public DbSet<Course> Courses { get; set; }
55+
public DbSet<Course> Courses { get; set; }
5656

57-
public DbSet<StudentCourse> StudentCourses { get; set; }
58-
}
57+
public DbSet<StudentCourse> StudentCourses { get; set; }
58+
}
5959

60-
public class TriggeredApplicationContext(DbContextOptions<TriggeredApplicationContext> options) : DbContext(options), IApplicationContextContract
61-
{
62-
protected override void OnModelCreating(ModelBuilder modelBuilder) => modelBuilder.Entity<StudentCourse>().HasKey(x => new { x.StudentId, x.CourseId });
60+
public class TriggeredApplicationContext(DbContextOptions<TriggeredApplicationContext> options) : DbContext(options), IApplicationContextContract
61+
{
62+
protected override void OnModelCreating(ModelBuilder modelBuilder) => modelBuilder.Entity<StudentCourse>().HasKey(x => new { x.StudentId, x.CourseId });
6363

64-
public DbSet<Student> Students { get; set; }
64+
public DbSet<Student> Students { get; set; }
6565

66-
public DbSet<Course> Courses { get; set; }
66+
public DbSet<Course> Courses { get; set; }
6767

68-
public DbSet<StudentCourse> StudentCourses { get; set; }
69-
}
68+
public DbSet<StudentCourse> StudentCourses { get; set; }
7069
}

benchmarks/EntityFrameworkCore.Triggered.Benchmarks/EmbracingFeaturesBenchmarks.cs

Lines changed: 98 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2,133 +2,132 @@
22
using Microsoft.EntityFrameworkCore;
33
using Microsoft.Extensions.DependencyInjection;
44

5-
namespace EntityFrameworkCore.Triggered.Benchmarks
5+
namespace EntityFrameworkCore.Triggered.Benchmarks;
6+
7+
[MemoryDiagnoser]
8+
public class EmbracingFeaturesBenchmarks
69
{
7-
[MemoryDiagnoser]
8-
public class EmbracingFeaturesBenchmarks
10+
private IServiceProvider _serviceProvider;
11+
12+
[GlobalSetup]
13+
public void GlobalSetup() => _serviceProvider = new ServiceCollection()
14+
.AddDbContext<ApplicationContext>(options => {
15+
options
16+
.UseInMemoryDatabase(nameof(WithDbContext));
17+
})
18+
.AddTriggeredDbContext<TriggeredApplicationContext>(options => {
19+
options
20+
.UseInMemoryDatabase(nameof(WithTriggeredDbContext))
21+
.UseTriggers(triggerOptions => {
22+
triggerOptions.AddTrigger<Triggers.SetStudentRegistrationDateTrigger>();
23+
triggerOptions.AddTrigger<Triggers.SignStudentUpForMandatoryCourses>();
24+
});
25+
})
26+
.BuildServiceProvider();
27+
28+
[Params(50)]
29+
public int OuterBatches;
30+
31+
[Params(1, 10, 100)]
32+
public int InnerBatches;
33+
34+
private void Validate(IApplicationContextContract applicationContextContract)
935
{
10-
private IServiceProvider _serviceProvider;
11-
12-
[GlobalSetup]
13-
public void GlobalSetup() => _serviceProvider = new ServiceCollection()
14-
.AddDbContext<ApplicationContext>(options => {
15-
options
16-
.UseInMemoryDatabase(nameof(WithDbContext));
17-
})
18-
.AddTriggeredDbContext<TriggeredApplicationContext>(options => {
19-
options
20-
.UseInMemoryDatabase(nameof(WithTriggeredDbContext))
21-
.UseTriggers(triggerOptions => {
22-
triggerOptions.AddTrigger<Triggers.SetStudentRegistrationDateTrigger>();
23-
triggerOptions.AddTrigger<Triggers.SignStudentUpForMandatoryCourses>();
24-
});
25-
})
26-
.BuildServiceProvider();
27-
28-
[Params(50)]
29-
public int OuterBatches;
30-
31-
[Params(1, 10, 100)]
32-
public int InnerBatches;
33-
34-
private void Validate(IApplicationContextContract applicationContextContract)
35-
{
36-
var studentCoursesCount = applicationContextContract.StudentCourses.Count();
37-
var expectedCoursesCount = OuterBatches * InnerBatches;
36+
var studentCoursesCount = applicationContextContract.StudentCourses.Count();
37+
var expectedCoursesCount = OuterBatches * InnerBatches;
3838

39-
if (studentCoursesCount != expectedCoursesCount)
40-
{
41-
throw new InvalidOperationException($"Found {studentCoursesCount}, expected {expectedCoursesCount}");
42-
}
39+
if (studentCoursesCount != expectedCoursesCount)
40+
{
41+
throw new InvalidOperationException($"Found {studentCoursesCount}, expected {expectedCoursesCount}");
4342
}
43+
}
4444

45-
[Benchmark(Baseline = true)]
46-
public void WithDbContext()
45+
[Benchmark(Baseline = true)]
46+
public void WithDbContext()
47+
{
48+
// setup
4749
{
48-
// setup
49-
{
50-
using var scope = _serviceProvider.CreateScope();
51-
using var context = scope.ServiceProvider.GetRequiredService<ApplicationContext>();
50+
using var scope = _serviceProvider.CreateScope();
51+
using var context = scope.ServiceProvider.GetRequiredService<ApplicationContext>();
5252

53-
context.Database.EnsureDeleted();
53+
context.Database.EnsureDeleted();
5454

55-
context.Courses.Add(new Course { Id = Guid.NewGuid(), DisplayName = "Test", IsMandatory = true });
56-
context.SaveChanges();
57-
}
55+
context.Courses.Add(new Course { Id = Guid.NewGuid(), DisplayName = "Test", IsMandatory = true });
56+
context.SaveChanges();
57+
}
5858

59-
// execute
60-
for (var outerBatch = 0; outerBatch < OuterBatches; outerBatch++)
61-
{
62-
using var scope = _serviceProvider.CreateScope();
63-
using var context = scope.ServiceProvider.GetRequiredService<ApplicationContext>();
59+
// execute
60+
for (var outerBatch = 0; outerBatch < OuterBatches; outerBatch++)
61+
{
62+
using var scope = _serviceProvider.CreateScope();
63+
using var context = scope.ServiceProvider.GetRequiredService<ApplicationContext>();
6464

65-
for (var innerBatch = 0; innerBatch < InnerBatches; innerBatch++)
66-
{
67-
var student = new Student { Id = Guid.NewGuid(), DisplayName = "Test" };
68-
student.RegistrationDate = DateTimeOffset.Now;
65+
for (var innerBatch = 0; innerBatch < InnerBatches; innerBatch++)
66+
{
67+
var student = new Student { Id = Guid.NewGuid(), DisplayName = "Test" };
68+
student.RegistrationDate = DateTimeOffset.Now;
6969

70-
context.Add(student);
70+
context.Add(student);
7171

72-
var mandatoryCourses = context.Courses.Where(x => x.IsMandatory).ToList();
72+
var mandatoryCourses = context.Courses.Where(x => x.IsMandatory).ToList();
7373

74-
foreach (var mandatoryCourse in mandatoryCourses)
75-
{
76-
context.StudentCourses.Add(new StudentCourse {
77-
CourseId = mandatoryCourse.Id,
78-
StudentId = student.Id
79-
});
80-
}
74+
foreach (var mandatoryCourse in mandatoryCourses)
75+
{
76+
context.StudentCourses.Add(new StudentCourse {
77+
CourseId = mandatoryCourse.Id,
78+
StudentId = student.Id
79+
});
8180
}
82-
83-
context.SaveChanges();
8481
}
8582

86-
// validate
87-
{
88-
using var scope = _serviceProvider.CreateScope();
89-
using var context = scope.ServiceProvider.GetRequiredService<ApplicationContext>();
90-
91-
Validate(context);
92-
}
83+
context.SaveChanges();
9384
}
9485

95-
[Benchmark]
96-
public void WithTriggeredDbContext()
86+
// validate
9787
{
98-
// setup
99-
{
100-
using var scope = _serviceProvider.CreateScope();
101-
using var context = scope.ServiceProvider.GetRequiredService<TriggeredApplicationContext>();
88+
using var scope = _serviceProvider.CreateScope();
89+
using var context = scope.ServiceProvider.GetRequiredService<ApplicationContext>();
10290

103-
context.Database.EnsureDeleted();
91+
Validate(context);
92+
}
93+
}
10494

105-
context.Courses.Add(new Course { Id = Guid.NewGuid(), DisplayName = "Test", IsMandatory = true });
106-
context.SaveChanges();
107-
}
95+
[Benchmark]
96+
public void WithTriggeredDbContext()
97+
{
98+
// setup
99+
{
100+
using var scope = _serviceProvider.CreateScope();
101+
using var context = scope.ServiceProvider.GetRequiredService<TriggeredApplicationContext>();
108102

109-
// execute
110-
for (var outerBatch = 0; outerBatch < OuterBatches; outerBatch++)
111-
{
112-
using var scope = _serviceProvider.CreateScope();
113-
using var context = scope.ServiceProvider.GetRequiredService<TriggeredApplicationContext>();
103+
context.Database.EnsureDeleted();
114104

115-
for (var innerBatch = 0; innerBatch < InnerBatches; innerBatch++)
116-
{
117-
var student = new Student { Id = Guid.NewGuid(), DisplayName = "Test" };
118-
context.Add(student);
119-
}
105+
context.Courses.Add(new Course { Id = Guid.NewGuid(), DisplayName = "Test", IsMandatory = true });
106+
context.SaveChanges();
107+
}
108+
109+
// execute
110+
for (var outerBatch = 0; outerBatch < OuterBatches; outerBatch++)
111+
{
112+
using var scope = _serviceProvider.CreateScope();
113+
using var context = scope.ServiceProvider.GetRequiredService<TriggeredApplicationContext>();
120114

121-
context.SaveChanges();
115+
for (var innerBatch = 0; innerBatch < InnerBatches; innerBatch++)
116+
{
117+
var student = new Student { Id = Guid.NewGuid(), DisplayName = "Test" };
118+
context.Add(student);
122119
}
123120

121+
context.SaveChanges();
122+
}
124123

125-
// validate
126-
{
127-
using var scope = _serviceProvider.CreateScope();
128-
using var context = scope.ServiceProvider.GetRequiredService<TriggeredApplicationContext>();
129124

130-
Validate(context);
131-
}
125+
// validate
126+
{
127+
using var scope = _serviceProvider.CreateScope();
128+
using var context = scope.ServiceProvider.GetRequiredService<TriggeredApplicationContext>();
129+
130+
Validate(context);
132131
}
133132
}
134133
}

0 commit comments

Comments
 (0)