1+ // Copyright (c) SimpleIdServer. All rights reserved.
2+ // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+ using DataSeeder ;
4+ using SimpleIdServer . IdServer . Domains ;
5+ using SimpleIdServer . IdServer . Stores ;
6+ using System . Collections . Generic ;
7+ using System . Threading ;
8+ using System . Threading . Tasks ;
9+
10+ namespace SimpleIdServer . IdServer . Migrations . Static ;
11+
12+ public class InitStaticApiResourceDataSeeder : BaseAfterDeploymentDataSeeder
13+ {
14+ private readonly IApiResourceRepository _apiResourceRepository ;
15+ private readonly ITransactionBuilder _transactionBuilder ;
16+ private readonly StaticApiResourcesDataSeeder _apiResourcesData ;
17+
18+ public InitStaticApiResourceDataSeeder (
19+ IApiResourceRepository apiResourceRepository ,
20+ ITransactionBuilder transactionBuilder ,
21+ StaticApiResourcesDataSeeder apiResourcesData ,
22+ IDataSeederExecutionHistoryRepository dataSeederExecutionHistoryRepository
23+ ) : base ( dataSeederExecutionHistoryRepository )
24+ {
25+ _apiResourceRepository = apiResourceRepository ;
26+ _transactionBuilder = transactionBuilder ;
27+ _apiResourcesData = apiResourcesData ;
28+ }
29+
30+ public override string Name => nameof ( InitStaticApiResourceDataSeeder ) ;
31+
32+ protected override async Task Execute ( CancellationToken cancellationToken )
33+ {
34+ using ( var transaction = _transactionBuilder . Build ( ) )
35+ {
36+ foreach ( var apiResource in _apiResourcesData . ApiResources )
37+ {
38+ _apiResourceRepository . Add ( apiResource ) ;
39+ }
40+
41+ await transaction . Commit ( cancellationToken ) ;
42+ }
43+ }
44+ }
45+ public class StaticApiResourcesDataSeeder
46+ {
47+ public StaticApiResourcesDataSeeder ( List < ApiResource > apiResources )
48+ {
49+ ApiResources = apiResources ;
50+ }
51+
52+ public List < ApiResource > ApiResources
53+ {
54+ get ; private set ;
55+ }
56+ }
0 commit comments