C
C#17mo ago
moon

❔ builder.Services.AddDbContext<>

builder.Services.AddDbContext<UygulamaDbContext>( options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddDbContext<UygulamaDbContext>( options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
The 'options' here, where did it exactly come from, and we were also able to access it by putting a dot (options.)? Is it something like the callback in JavaScript?
5 Replies
Angius
Angius17mo ago
It comes from the lambda
private SomeOptions _options = new();

public void DoStuff(Action<SomeOptions> setOptions)
{
setOptions(_options);
}
private SomeOptions _options = new();

public void DoStuff(Action<SomeOptions> setOptions)
{
setOptions(_options);
}
thing.DoStuff(options => {
options.Name = "hello";
options.Count = 78;
});
thing.DoStuff(options => {
options.Name = "hello";
options.Count = 78;
});
Angius
Angius17mo ago
Because SomeOptions is a reference type, this is roughly what happens:
JakenVeina
JakenVeina17mo ago
it is precisely like a callback in JavaScript
moon
moonOP17mo ago
thanks a lot got it thanks
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?