forked from VahidN/EFCoreSecondLevelCacheInterceptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
35 lines (30 loc) · 1.07 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Linq;
using EFCoreSecondLevelCacheInterceptor.Tests.DataLayer.Entities;
using EFCoreSecondLevelCacheInterceptor.Tests.DataLayer.Utils;
using Microsoft.Extensions.DependencyInjection;
namespace EFCoreSecondLevelCacheInterceptor.ConsoleSample
{
class Program
{
static void Main(string[] args)
{
initDb();
EFServiceProvider.RunInContext(context =>
{
context.Posts.Add(new Post { Title = "Title 1", UserId = 1 });
context.SaveChanges();
var posts = context.Posts.Cacheable().ToList();
Console.WriteLine($"Title From DB: {posts.First().Title}");
posts = context.Posts.Cacheable().ToList();
Console.WriteLine($"Title From Cache: {posts.First().Title}");
});
}
private static void initDb()
{
var serviceScope = EFServiceProvider.GetRequiredService<IServiceScopeFactory>();
serviceScope.Initialize();
serviceScope.SeedData();
}
}
}