Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

EntityFrameworkServicesBuilder.TryAdd Method

Definition

Namespace:
Microsoft.EntityFrameworkCore.Infrastructure
Assembly:
Microsoft.EntityFrameworkCore.dll
Package:
Microsoft.EntityFrameworkCore v10.0.0
Package:
Microsoft.EntityFrameworkCore v2.0.3
Package:
Microsoft.EntityFrameworkCore v2.1.11
Package:
Microsoft.EntityFrameworkCore v2.2.6
Package:
Microsoft.EntityFrameworkCore v3.0.0
Package:
Microsoft.EntityFrameworkCore v3.1.0
Package:
Microsoft.EntityFrameworkCore v5.0.0
Package:
Microsoft.EntityFrameworkCore v6.0.0
Package:
Microsoft.EntityFrameworkCore v7.0.0
Package:
Microsoft.EntityFrameworkCore v8.0.0
Package:
Microsoft.EntityFrameworkCore v9.0.0

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Overloads

Name Description
TryAdd(Type, Object)

Adds an implementation of an Entity Framework service only if one has not already been registered. This method can only be used for singleton services.

TryAdd(Type, Type)

Adds an implementation of an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

TryAdd(Type, Type, Func<IServiceProvider,Object>)

Adds a factory for an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

TryAdd<TService,TImplementation>()

Adds an implementation of an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

TryAdd<TService,TImplementation>(Func<IServiceProvider,TImplementation>)

Adds a factory for an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

TryAdd<TService>(Func<IServiceProvider,TService>)

Adds a factory for an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

TryAdd<TService>(TService)

Adds an implementation of an Entity Framework service only if one has not already been registered. This method can only be used for singleton services.

TryAdd(Type, Object)

Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs

Adds an implementation of an Entity Framework service only if one has not already been registered. This method can only be used for singleton services.

public virtual Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder TryAdd(Type serviceType, object implementation);
abstract member TryAdd : Type * obj -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder
override this.TryAdd : Type * obj -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder
Public Overridable Function TryAdd (serviceType As Type, implementation As Object) As EntityFrameworkServicesBuilder

Parameters

serviceType
Type

The contract for the service.

implementation
Object

The implementation of the service.

Returns

This builder, such that further calls can be chained.

Remarks

See Implementation of database providers and extensions for more information and examples.

Applies to

TryAdd(Type, Type)

Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs

Adds an implementation of an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

public virtual Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder TryAdd(Type serviceType, Type implementationType);
abstract member TryAdd : Type * Type -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder
override this.TryAdd : Type * Type -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder
Public Overridable Function TryAdd (serviceType As Type, implementationType As Type) As EntityFrameworkServicesBuilder

Parameters

serviceType
Type

The contract for the service.

implementationType
Type

The concrete type that implements the service.

Returns

This builder, such that further calls can be chained.

Remarks

See Implementation of database providers and extensions for more information and examples.

Applies to

TryAdd(Type, Type, Func<IServiceProvider,Object>)

Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs

Adds a factory for an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

public virtual Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder TryAdd(Type serviceType, Type implementationType, Func<IServiceProvider,object> factory);
abstract member TryAdd : Type * Type * Func<IServiceProvider, obj> -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder
override this.TryAdd : Type * Type * Func<IServiceProvider, obj> -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder
Public Overridable Function TryAdd (serviceType As Type, implementationType As Type, factory As Func(Of IServiceProvider, Object)) As EntityFrameworkServicesBuilder

Parameters

serviceType
Type

The contract for the service.

implementationType
Type

The concrete type that implements the service.

factory
Func<IServiceProvider,Object>

The factory that will create the service instance.

Returns

This builder, such that further calls can be chained.

Remarks

See Implementation of database providers and extensions for more information and examples.

Applies to

TryAdd<TService,TImplementation>()

Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs

Adds an implementation of an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

public virtual Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder TryAdd<TService,TImplementation>() where TService : class where TImplementation : class, TService;
abstract member TryAdd : unit -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder (requires 'Service : null)
override this.TryAdd : unit -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder (requires 'Service : null)
Public Overridable Function TryAdd(Of TService As Class, TImplementation As Class) () As EntityFrameworkServicesBuilder

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

Returns

This builder, such that further calls can be chained.

Remarks

See Implementation of database providers and extensions for more information and examples.

Applies to

TryAdd<TService,TImplementation>(Func<IServiceProvider,TImplementation>)

Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs

Adds a factory for an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

public virtual Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder TryAdd<TService,TImplementation>(Func<IServiceProvider,TImplementation> factory) where TService : class where TImplementation : class, TService;
abstract member TryAdd : Func<IServiceProvider, #'Service> -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder (requires 'Service : null)
override this.TryAdd : Func<IServiceProvider, #'Service> -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder (requires 'Service : null)
Public Overridable Function TryAdd(Of TService As Class, TImplementation As Class) (factory As Func(Of IServiceProvider, TImplementation)) As EntityFrameworkServicesBuilder

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

Parameters

factory
Func<IServiceProvider,TImplementation>

The factory that will create the service instance.

Returns

This builder, such that further calls can be chained.

Remarks

See Implementation of database providers and extensions for more information and examples.

Applies to

TryAdd<TService>(Func<IServiceProvider,TService>)

Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs

Adds a factory for an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

public virtual Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder TryAdd<TService>(Func<IServiceProvider,TService> factory) where TService : class;
abstract member TryAdd : Func<IServiceProvider, 'Service (requires 'Service : null)> -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder (requires 'Service : null)
override this.TryAdd : Func<IServiceProvider, 'Service (requires 'Service : null)> -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder (requires 'Service : null)
Public Overridable Function TryAdd(Of TService As Class) (factory As Func(Of IServiceProvider, TService)) As EntityFrameworkServicesBuilder

Type Parameters

TService

The contract for the service.

Parameters

factory
Func<IServiceProvider,TService>

The factory that will create the service instance.

Returns

This builder, such that further calls can be chained.

Remarks

See Implementation of database providers and extensions for more information and examples.

Applies to

TryAdd<TService>(TService)

Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs
Source:
EntityFrameworkServicesBuilder.cs

Adds an implementation of an Entity Framework service only if one has not already been registered. This method can only be used for singleton services.

public virtual Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder TryAdd<TService>(TService implementation) where TService : class;
abstract member TryAdd : 'Service -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder (requires 'Service : null)
override this.TryAdd : 'Service -> Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder (requires 'Service : null)
Public Overridable Function TryAdd(Of TService As Class) (implementation As TService) As EntityFrameworkServicesBuilder

Type Parameters

TService

The contract for the service.

Parameters

implementation
TService

The implementation of the service.

Returns

This builder, such that further calls can be chained.

Remarks

See Implementation of database providers and extensions for more information and examples.

Applies to


Feedback

Was this page helpful?