vkhorikov / efcoreencapsulation Goto Github PK
View Code? Open in Web Editor NEWSource code for the course Encapsulating EF Core Usage
Home Page: https://enterprisecraftsmanship.com/ps-ef-core-2
License: MIT License
Source code for the course Encapsulating EF Core Usage
Home Page: https://enterprisecraftsmanship.com/ps-ef-core-2
License: MIT License
More of a question than an issue since the course does not speak about adding migrations. I am getting the following error when trying to add a new migration script using the add-migration command. The verbose switch reveals this:
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'MyDBContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
---> System.InvalidOperationException: Unable to resolve service for type 'System.String' while attempting to activate 'MyEFCoreProject.EntityFrameworkCore.MyDBContext'.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass21_4.b__13()
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass21_4.b__13()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func1 factory) at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0
1.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Not quite sure what I am doing wrong. I also reverted the constructor and registration back to the original before your encapsulation modifications and also got an error message.
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1
Program.cs
//builder.Services.AddScoped(_ => new PaceFillsContext(builder.Configuration["ConnectionString"], true));
builder.Services.AddDbContext(options =>
options.UseSqlServer(builder.Configuration["ConnectionString"]));
Before builder.Build() is called
public MyDBContext(DbContextOptions options) : base(options)
{
}
//public MyDBContext(string connectionString, bool useConsoleLogger)
//{
// _connectionString = connectionString;
// _useConsoleLogger = useConsoleLogger;
//}
Good afternoon.
I looked at your course and I had a question.
You are considering the context connection option as AddContext()
. In this case, everything is fine in your example. But what if I want to use AddPooledDbContextFactory()
. How do I implement a factory and encapsulate the logic?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.