I created an ASP.NET Core 2.2 Application, in Startup.cs
I have this:
services.AddEntityFrameworkSqlServer();
services.AddScoped<ILazyLoader, MyLazyLoader>();
services.AddDbContext<ModelContext>(builder =>
{
builder.UseLazyLoadingProxies();
builder.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
var options = builder.Options;
services.AddSingleton(options);
});
But the lazyloader is not changed, what do I need to change do make this change?
Remove the first two lines
services.AddEntityFrameworkSqlServer();
services.AddScoped<ILazyLoader, MyLazyLoader>();
and setup the EFC related stuff inside AddDbContext
builder action.
builder.UseSqlServer
will do internally AddEntityFrameworkSqlServer()
, and to replace the ILazyLoader
service , use - well, ReplaceService
method:
services.AddDbContext<ModelContext>(builder =>
{
builder.ReplaceService<ILazyLoader, MyLazyLoader>();
// ...
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.