Skip to content

Commit 1786a18

Browse files
simplify visitors.
1 parent 2b2ecd2 commit 1786a18

File tree

2 files changed

+8
-32
lines changed

2 files changed

+8
-32
lines changed

src/ResourceManager/Common/Commands.Common.Strategies/GetStateExtensions.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class GetStateExtensions
1515
/// <param name="cancellationToken"></param>
1616
/// <returns></returns>
1717
public static async Task<IState> GetStateAsync<TModel>(
18-
this IEntityConfig<TModel> config,
18+
this ResourceConfig<TModel> config,
1919
IClient client,
2020
CancellationToken cancellationToken)
2121
where TModel : class
@@ -25,7 +25,7 @@ public static async Task<IState> GetStateAsync<TModel>(
2525
return context.Result;
2626
}
2727

28-
static Task GetStateAsyncDispatch(this StateOperationContext context, IEntityConfig config)
28+
static Task GetStateAsyncDispatch(this StateOperationContext context, IResourceConfig config)
2929
=> config.Accept(new GetStateAsyncVisitor(), context);
3030

3131
static async Task GetStateAsync<TModel>(
@@ -39,30 +39,18 @@ static async Task GetStateAsync<TModel>(
3939
// Get state of dependencies if the resource doesn't exist
4040
if (info == null)
4141
{
42-
var tasks = config.Dependencies.Select(context.GetStateAsyncDispatch);
42+
var tasks = config.GetResourceDependencies().Select(context.GetStateAsyncDispatch);
4343
await Task.WhenAll(tasks);
4444
}
4545
return info;
4646
});
4747

48-
static Task GetStateAsync<TModel, TParentModel>(
49-
this StateOperationContext context, NestedResourceConfig<TModel, TParentModel> config)
50-
where TModel : class
51-
where TParentModel : class
52-
=> context.GetStateAsyncDispatch(config.Parent);
53-
54-
sealed class GetStateAsyncVisitor : IEntityConfigVisitor<StateOperationContext, Task>
48+
sealed class GetStateAsyncVisitor : IResourceConfigVisitor<StateOperationContext, Task>
5549
{
5650
public Task Visit<TModel>(
5751
ResourceConfig<TModel> config, StateOperationContext context)
5852
where TModel : class
5953
=> context.GetStateAsync(config);
60-
61-
public Task Visit<TModel, TParentModel>(
62-
NestedResourceConfig<TModel, TParentModel> config, StateOperationContext context)
63-
where TModel : class
64-
where TParentModel : class
65-
=> context.GetStateAsync(config);
6654
}
6755
}
6856
}

src/ResourceManager/Common/Commands.Common.Strategies/LocationExtensions.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ public static class LocationExtensions
1111
/// <param name="state"></param>
1212
/// <param name="config"></param>
1313
/// <returns></returns>
14-
public static string GetLocation(this IState state, IEntityConfig config)
14+
public static string GetLocation(this IState state, IResourceConfig config)
1515
=> state.GetDependencyLocationDispatch(config)?.Location;
1616

17-
static DependencyLocation GetDependencyLocationDispatch(this IState state, IEntityConfig config)
17+
static DependencyLocation GetDependencyLocationDispatch(this IState state, IResourceConfig config)
1818
=> config.Accept(new GetDependencyLocationVisitor(), state);
1919

2020
static DependencyLocation GetDependencyLocation<TModel>(
@@ -27,28 +27,16 @@ static DependencyLocation GetDependencyLocation<TModel>(
2727
config.Strategy.GetLocation(info),
2828
typeof(TModel) != typeof(ResourceGroup))
2929
: config
30-
.Dependencies
30+
.GetResourceDependencies()
3131
.Select(state.GetDependencyLocationDispatch)
3232
.Aggregate(null as DependencyLocation, Merge);
3333
}
3434

35-
static DependencyLocation GetDependencyLocation<TModel, TParentModel>(
36-
this IState state, NestedResourceConfig<TModel, TParentModel> config)
37-
where TModel : class
38-
where TParentModel : class
39-
=> config.Parent.Accept(new GetDependencyLocationVisitor(), state);
40-
41-
sealed class GetDependencyLocationVisitor : IEntityConfigVisitor<IState, DependencyLocation>
35+
sealed class GetDependencyLocationVisitor : IResourceConfigVisitor<IState, DependencyLocation>
4236
{
4337
public DependencyLocation Visit<TModel>(ResourceConfig<TModel> config, IState state)
4438
where TModel : class
4539
=> state.GetDependencyLocation(config);
46-
47-
public DependencyLocation Visit<TModel, TParentModel>(
48-
NestedResourceConfig<TModel, TParentModel> config, IState state)
49-
where TModel : class
50-
where TParentModel : class
51-
=> state.GetDependencyLocation(config);
5240
}
5341

5442
sealed class DependencyLocation

0 commit comments

Comments
 (0)