C
C#9mo 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
Angius9mo 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
Angius9mo ago
Because SomeOptions is a reference type, this is roughly what happens:
JakenVeina
JakenVeina9mo ago
it is precisely like a callback in JavaScript
moon
moon9mo ago
thanks a lot got it thanks
Accord
Accord9mo 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.