Skip to content

Commit 6a1f2da

Browse files
feat(Select): support inject LookupService
Co-Authored-By: Diego2098 <[email protected]>
1 parent ece2207 commit 6a1f2da

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/BootstrapBlazor/Components/Select/Select.razor.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ public partial class Select<TValue> : ISelect
235235
[NotNull]
236236
private IStringLocalizer<Select<TValue>>? Localizer { get; set; }
237237

238+
/// <summary>
239+
/// 获得/设置 <see cref="ILookupService"/> 服务实例
240+
/// </summary>
241+
[Inject]
242+
[NotNull]
243+
private ILookupService? InjectLookupService { get; set; }
244+
238245
/// <summary>
239246
/// 获得 input 组件 Id 方法
240247
/// </summary>
@@ -371,13 +378,15 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
371378
private async Task<IEnumerable<SelectedItem>> GetItemsAsync()
372379
{
373380
IEnumerable<SelectedItem>? items = null;
374-
if (LookupService != null)
381+
if (!string.IsNullOrEmpty(LookupServiceKey))
375382
{
376-
items = await LookupService.GetItemsByKeyAsync(LookupServiceKey, LookupServiceData);
383+
items = await GetLookupService().GetItemsAsync(LookupServiceKey, LookupServiceData);
377384
}
378385
return items ?? [];
379386
}
380387

388+
private ILookupService GetLookupService() => LookupService ?? InjectLookupService;
389+
381390
/// <summary>
382391
/// 获得/设置 数据总条目
383392
/// </summary>

0 commit comments

Comments
 (0)