-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathProgram.cs
More file actions
28 lines (23 loc) · 1.03 KB
/
Program.cs
File metadata and controls
28 lines (23 loc) · 1.03 KB
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
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using TanvirArjel.EFCore.GenericRepository;
namespace GenericRepositoryExercise
{
internal class Program
{
static async Task Main(string[] args)
{
//设置依赖注入容器
IServiceCollection services = new ServiceCollection();
services.AddScoped<UserInfoService>();
var connectionString = "Server=.;Database=MyTestDB;User Id=test;Password=123456;trustServerCertificate=true;";
services.AddDbContext<TestDbContext>(option => option.UseSqlServer(connectionString));
//注册DbConext后立即调用它
services.AddGenericRepository<TestDbContext>();
IServiceProvider serviceProvider = services.BuildServiceProvider();
//从容器中获取UserInfoService实例并执行操作
var userInfoService = serviceProvider.GetRequiredService<UserInfoService>();
await userInfoService.UserInfoCRUD();
}
}
}