Skip to content

Commit 2c12b95

Browse files
committed
Updated samples to use modern trigger registration
1 parent d6243cf commit 2c12b95

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

samples/v2/2 - PrimarySchool/Program.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ class Program
1212
static void Main(string[] args)
1313
{
1414
var serviceProvider = new ServiceCollection()
15-
.AddTriggeredDbContext<ApplicationDbContext>(options => {
15+
.AddDbContext<ApplicationDbContext>(options => {
1616
options
17-
.UseInMemoryDatabase("PrimarySchool");
17+
.UseInMemoryDatabase("PrimarySchool")
18+
.UseTriggers(triggerOptions => {
19+
triggerOptions.AddTrigger<Triggers.StudentSignupToMandatoryCourses>();
20+
});
1821
})
19-
.AddScoped<IBeforeSaveTrigger<Student>, Triggers.StudentSignupToMandatoryCourses>()
2022
.BuildServiceProvider();
2123

2224
var serviceScope = serviceProvider.CreateScope();

samples/v2/3 - StudentManagerAspNetCore/Startup.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ public void ConfigureServices(IServiceCollection services)
3333
services
3434
.AddTriggeredDbContextPool<ApplicationDbContext>(options => {
3535
options
36-
.UseSqlite("Data source=test.db");
36+
.UseSqlite("Data source=test.db")
37+
.UseTriggers(triggerOptions => {
38+
triggerOptions.AddTrigger<Triggers.Traits.Audited.CreateAuditRecord>();
39+
triggerOptions.AddTrigger<Triggers.Traits.SoftDelete.EnsureSoftDelete>();
40+
triggerOptions.AddTrigger<Triggers.Courses.AutoSignupStudents>();
41+
triggerOptions.AddTrigger<Triggers.StudentCourses.BlockRemovalWhenCourseIsMandatory>();
42+
triggerOptions.AddTrigger<Triggers.StudentCourses.SendWelcomingEmail>();
43+
triggerOptions.AddTrigger<Triggers.Students.AssignRegistrationDate>();
44+
triggerOptions.AddTrigger<Triggers.Students.SignupToMandatoryCourses>();
45+
});
3746
})
38-
.AddHttpContextAccessor()
39-
.AddScoped<IBeforeSaveTrigger<Traits.ISoftDelete>, Triggers.Traits.SoftDelete.EnsureSoftDelete>()
40-
.AddScoped<IBeforeSaveTrigger<Traits.IAudited>, Triggers.Traits.Audited.CreateAuditRecord>()
41-
42-
.AddScoped<IBeforeSaveTrigger<Course>, Triggers.Courses.AutoSignupStudents>()
43-
.AddScoped<IBeforeSaveTrigger<Student>, Triggers.Students.AssignRegistrationDate>()
44-
.AddScoped<IBeforeSaveTrigger<Student>, Triggers.Students.SignupToMandatoryCourses>()
45-
.AddScoped<IBeforeSaveTrigger<StudentCourse>, Triggers.StudentCourses.BlockRemovalWhenCourseIsMandatory>()
46-
.AddScoped<IAfterSaveTrigger<StudentCourse>, Triggers.StudentCourses.SendWelcomingEmail>();
47+
.AddHttpContextAccessor();
4748
}
4849

4950
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

samples/v2/4 - BlazorTests/4 - BlazorTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="EntityFrameworkCore.Triggered" Version="$(EFCoreTriggeredPackageVersion)" />
10+
<PackageReference Include="EntityFrameworkCore.Triggered.Extensions" Version="$(EFCoreTriggeredPackageVersion)" />
1111
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(EFCorePackageVersion)" />
1212
</ItemGroup>
1313

samples/v2/4 - BlazorTests/Startup.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ public void ConfigureServices(IServiceCollection services)
3232
services.AddServerSideBlazor();
3333
services.AddSingleton<EventAggregator>();
3434

35-
services.AddTriggeredDbContextFactory<ApplicationDbContext>(options => {
35+
services.AddDbContextFactory<ApplicationDbContext>(options => {
3636
options
37-
.UseSqlite("Data source=test.db");
38-
})
39-
.AddScoped<IBeforeSaveTrigger<Count>, Triggers.Counts.SetCreatedOn>()
40-
.AddScoped<IAfterSaveTrigger<Count>, Triggers.Counts.PublishCountAddedEvent>();
37+
.UseSqlite("Data source=test.db")
38+
.UseTriggers(triggerOptions => {
39+
triggerOptions.AddAssemblyTriggers();
40+
});
41+
});
4142
}
4243

4344
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

samples/v2/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
33
<EFCorePackageVersion Condition=" '$(EFCorePackageVersion)'=='' ">5.0.0</EFCorePackageVersion>
4-
<EFCoreTriggeredPackageVersion Condition=" '$(EFCoreTriggeredPackageVersion )'=='' ">2.2.0</EFCoreTriggeredPackageVersion>
4+
<EFCoreTriggeredPackageVersion Condition=" '$(EFCoreTriggeredPackageVersion )'=='' ">2.3.0-beta.1</EFCoreTriggeredPackageVersion>
55
</PropertyGroup>
66
</Project>

0 commit comments

Comments
 (0)