Service is the convenience property supplied by OwningComponentBase<T>. In a Blazor component inheriting OwningComponentBase<DataContext>, Service exposes the component's scoped DataContext without resolving it manually. section 36.3.1
This typed base creates a component-specific scope, isolating Entity Framework Core changes from other components that share Blazor's persistent connection. The component can access its context through Service and avoid resolving it from ScopedServices. section 36.3.1
Using Service in an editor component
Declare @inherits OwningComponentBase<DataContext>, then expose the context with `DataContext? Context => Service;`. The editor can use Context for its data operations while NavigationManager remains injected normally. section 36.3.1
Listing 36.16 Using the typed base in the Editor.razor file in the Blazor/Forms folder
@page "/forms/edit/{id:long}"
@layout EmptyLayout
@inherits OwningComponentBase<DataContext>
<link href="/blazorValidation.css" rel="stylesheet" />
<h4 class="bg-primary text-center text-white p-2">Edit</h4>
<h6 class="bg-info text-center text-white p-2">@FormSubmitMessage</h6>
<!-- ...elements omitted for brevity... -->
@code {
[Inject]
public NavigationManager? NavManager { get; set; }
//[Inject]
DataContext? Context => Service;
[Parameter]
public long Id { get; set; }
// ...statements omitted for brevity...
}
Shows the typed OwningComponentBase<DataContext> declaration and the Context property mapped directly to Service. section 36.3.1
