-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added change event handler to receive notifications when something ch…
…ange on an IEntityType, it works only if Compacted Replicator is in use (#120) * Added change event handler to receive notifications when something change on an IEntityType, it works only if Compacted Replicator is in use * Added template for events * Update template identity
- Loading branch information
1 parent
480f785
commit f749390
Showing
13 changed files
with
242 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
src/net/templates/templates/kefcoreAppWithEvents/.template.config/template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"author": "MASES s.r.l.", | ||
"classifications": [ "Common", "Library" ], | ||
"identity": "MASES.EntityFrameworkCore.KNet.Templates.AppWithEvents", | ||
"name": "Executable template: Simple Console with events for EntityFrameworkCore provider for Apache Kafka project", | ||
"shortName": "kefcoreAppWithEvents", | ||
"tags": { | ||
"language": "C#", | ||
"type": "project" | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
src/net/templates/templates/kefcoreAppWithEvents/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using MASES.EntityFrameworkCore.KNet.Infrastructure; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace MASES.EntityFrameworkCore.KNet.Templates | ||
{ | ||
partial class Program | ||
{ | ||
static void OnEvent(IEntityType entity, bool state, object key) | ||
{ | ||
Console.WriteLine($"Entity {entity.Name} has {(state ? "removed" : "added/updated")} the key {key}"); | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
BloggingContext context = null; | ||
try | ||
{ | ||
context = new BloggingContext() | ||
{ | ||
BootstrapServers = "KAFKA-BROKER:9092", | ||
ApplicationId = "MyApplicationId", | ||
DbName = "MyDB", | ||
OnChangeEvent = OnEvent | ||
}; | ||
// cleanup topics on Broker | ||
context.Database.EnsureDeleted(); | ||
context.Database.EnsureCreated(); | ||
|
||
// prefill data | ||
for (int i = 0; i < 1000; i++) | ||
{ | ||
context.Add(new Blog | ||
{ | ||
Url = "http://blogs.msdn.com/adonet" + i.ToString(), | ||
Posts = new List<Post>() | ||
{ | ||
new Post() | ||
{ | ||
Title = "title", | ||
Content = i.ToString() | ||
} | ||
}, | ||
Rating = i, | ||
}); | ||
} | ||
// save data | ||
context.SaveChanges(); | ||
|
||
// make some queries | ||
var selector = (from op in context.Blogs | ||
join pg in context.Posts on op.BlogId equals pg.BlogId | ||
where pg.BlogId == op.BlogId | ||
select new { pg, op }); | ||
var pageObject = selector.FirstOrDefault(); | ||
|
||
var post = context.Posts.Single(b => b.BlogId == 2); | ||
|
||
post = context.Posts.Single(b => b.BlogId == 1); | ||
|
||
var all = context.Posts.All((o) => true); | ||
|
||
var value = context.Blogs.AsQueryable().ToQueryString(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.ToString()); | ||
} | ||
finally | ||
{ | ||
context?.Dispose(); | ||
} | ||
} | ||
} | ||
|
||
public class BloggingContext : KafkaDbContext | ||
{ | ||
// uncomment for persistent storage | ||
// public override bool UsePersistentStorage { get; set; } = true; | ||
|
||
// uncomment to disable compacted replicator | ||
//public override bool UseCompactedReplicator { get; set; } = false; | ||
|
||
public DbSet<Blog> Blogs { get; set; } | ||
public DbSet<Post> Posts { get; set; } | ||
|
||
/// uncomment for model builder | ||
//protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
//{ | ||
// modelBuilder.Entity<Blog>().HasKey(c => new { c.BlogId, c.Rating }); | ||
//} | ||
} | ||
|
||
public class Blog | ||
{ | ||
public int BlogId { get; set; } | ||
public string Url { get; set; } | ||
public int Rating { get; set; } | ||
public List<Post> Posts { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"BlogId: {BlogId} Url: {Url} Rating: {Rating}"; | ||
} | ||
} | ||
|
||
public class Post | ||
{ | ||
public int PostId { get; set; } | ||
public string Title { get; set; } | ||
public string Content { get; set; } | ||
|
||
public int BlogId { get; set; } | ||
public Blog Blog { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"PostId: {PostId} Title: {Title} Content: {Content} BlogId: {BlogId}"; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/net/templates/templates/kefcoreAppWithEvents/kefcoreAppWithEvents.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<LangVersion>latest</LangVersion> | ||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup Condition="Exists('..\..\..\KEFCore\KEFCore.csproj')"> | ||
<!--Within GitHub repo: used for test purpose--> | ||
<ProjectReference Include="..\..\..\KEFCore\KEFCore.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup Condition="!Exists('..\..\..\KEFCore\KEFCore.csproj')"> | ||
<!--Outside GitHub repo--> | ||
<PackageReference Include="MASES.EntityFrameworkCore.KNet" Version="0.10.1" IncludeAssets="All" PrivateAssets="None" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.