-
Notifications
You must be signed in to change notification settings - Fork 390
Expand file tree
/
Copy pathSeedDataExtension.cs
More file actions
26 lines (24 loc) · 819 Bytes
/
Copy pathSeedDataExtension.cs
File metadata and controls
26 lines (24 loc) · 819 Bytes
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
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SampleWebApiAspNetCore.Data;
using SampleWebApiAspNetCore.Service.Services.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SampleWebApiAspNetCore.Service.Helpers
{
public static class SeedDataExtension
{
public static void SeedData(this WebApplication app)
{
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<FoodDbContext>();
var seedDataService = scope.ServiceProvider.GetRequiredService<ISeedDataService>();
seedDataService.Initialize(dbContext);
}
}
}
}