AccessorExtensions.GetService Method

Definition

Overloads

GetService(IInfrastructure<IServiceProvider>, Type)

Resolves a service from the IServiceProvider exposed from a type that implements IInfrastructure<T>.

GetService<TService>(IInfrastructure<IServiceProvider>)

Resolves a service from the IServiceProvider exposed from a type that implements IInfrastructure<T>.

GetService(IInfrastructure<IServiceProvider>, Type)

Source:
AccessorExtensions.cs
Source:
AccessorExtensions.cs

Resolves a service from the IServiceProvider exposed from a type that implements IInfrastructure<T>.

C#
[System.Diagnostics.DebuggerStepThrough]
public static object GetService (this Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<IServiceProvider> accessor, Type serviceType);

Parameters

accessor
IInfrastructure<IServiceProvider>

The object exposing the service provider.

serviceType
Type

The type of service to be resolved.

Returns

The requested service.

Attributes

Remarks

IInfrastructure<T> is used to hide properties that are not intended to be used in application code but can be used in extension methods written by database providers etc.

See Accessing DbContext services for more information and examples.

Applies to

Entity Framework Core 9.0 and Entity Framework Core 8.0
Product Versions
Entity Framework Core 8.0, 9.0

GetService<TService>(IInfrastructure<IServiceProvider>)

Source:
AccessorExtensions.cs
Source:
AccessorExtensions.cs
Source:
AccessorExtensions.cs
Source:
AccessorExtensions.cs
Source:
AccessorExtensions.cs
Source:
AccessorExtensions.cs
Source:
AccessorExtensions.cs
Source:
AccessorExtensions.cs
Source:
AccessorExtensions.cs

Resolves a service from the IServiceProvider exposed from a type that implements IInfrastructure<T>.

C#
public static TService GetService<TService> (this Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<IServiceProvider> accessor);
C#
[System.Diagnostics.DebuggerStepThrough]
public static TService GetService<TService> (this Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<IServiceProvider> accessor);
C#
[System.Diagnostics.DebuggerStepThrough]
public static TService GetService<TService> (this Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<IServiceProvider> accessor) where TService : class;

Type Parameters

TService

The type of service to be resolved.

Parameters

accessor
IInfrastructure<IServiceProvider>

The object exposing the service provider.

Returns

TService

The requested service.

Attributes

Remarks

IInfrastructure<T> is used to hide properties that are not intended to be used in application code but can be used in extension methods written by database providers etc.

See Accessing DbContext services for more information and examples.

Applies to

Entity Framework Core 9.0 and other versions
Product Versions
Entity Framework Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0