DbConfiguration.SetContextFactory Method
Assembly: EntityFramework (in EntityFramework.dll)
Name | Description | |
---|---|---|
![]() | SetContextFactory(Type, Func<DbContext>) | Call this method from the constructor of a class derived from DbConfiguration to set a factory to allow DbContextInfo to create instances of a context that does not have a public, parameterless constructor. |
![]() | SetContextFactory<TContext>(Func<TContext>) | Call this method from the constructor of a class derived from DbConfiguration to set a factory to allow DbContextInfo to create instances of a context that does not have a public, parameterless constructor. |
DbConfiguration.SetContextFactory Method (Type, Func<DbContext>)
Call this method from the constructor of a class derived from DbConfiguration to set a factory to allow DbContextInfo to create instances of a context that does not have a public, parameterless constructor.
Parameters
- contextType
-
Type:
System.Type
The context type for which the factory should be used.
- factory
-
Type:
System.Func<DbContext>
The delegate to use to create context instances.
This is typically needed to allow design-time tools like Migrations or scaffolding code to use contexts that do not have public, parameterless constructors. This method is provided as a convenient and discoverable way to add configuration to the Entity Framework. Internally it works in the same way as using AddDependencyResolver to add an appropriate resolver for Func<TResult> with the context Type as the key. This means that, if desired, the same functionality can be achieved using a custom resolver or a resolver backed by an Inversion-of-Control container.
DbConfiguration.SetContextFactory<TContext> Method (Func<TContext>)
Call this method from the constructor of a class derived from DbConfiguration to set a factory to allow DbContextInfo to create instances of a context that does not have a public, parameterless constructor.
This is typically needed to allow design-time tools like Migrations or scaffolding code to use contexts that do not have public, parameterless constructors. This method is provided as a convenient and discoverable way to add configuration to the Entity Framework. Internally it works in the same way as using AddDependencyResolver to add an appropriate resolver for Func<TResult> with the context Type as the key. This means that, if desired, the same functionality can be achieved using a custom resolver or a resolver backed by an Inversion-of-Control container.