C
C#15mo 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
Angius15mo 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
Angius15mo ago
Because SomeOptions is a reference type, this is roughly what happens:
JakenVeina
JakenVeina15mo ago
it is precisely like a callback in JavaScript
moon
moonOP15mo ago
thanks a lot got it thanks
Accord
Accord15mo 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.
Want results from more Discord servers?
Add your server