SUPER MEGA T REX
SUPER MEGA T REX
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
No worries
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
I don't use EF at all I'm afraid
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
🙂
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
e.g. you don't want to store things with just their ids in case you store book id 1234 and then accidentally retrieve that book when trying to get user id 1234
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
Also if your cache is string keyed, make sure you identify it properly
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
You too, GL with your code
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
The service doesn't care whether it comes from a cache or not, it just asks for a book
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
So the caching is transparent to the consumer
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
E.g. IGetBookFromDatabase would be the interface, GetBookFromSqlDatabase physically goes to the DB, CachedGetBookFromDatabase takes a cache and an IGetBookFromDatabase
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
You'd generally use a cache to implement the same interface as the thing that retrieves the data, though
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
What to cache, how long to cache it etc completely depends on the data
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
Caching is an extremely nuanced topic
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
Sounds like you've got it nailed
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
But the actual OpenAiManager constructor won't be called until something asks the service collection for one
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
Generally you can treat the two as the same
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
Registers yes, instantiates when it is first resolved
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
var foo = new OpenAiManager();
services.AddSingleton(foo);
var foo = new OpenAiManager();
services.AddSingleton(foo);
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
If you really wanted to control the instantiation
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
There's also an overload to register an instance
113 replies
CC#
Created by antimatter8189 on 4/27/2023 in #help
❔ How does one hold a value in a private field in a controller?
And then yes, the same instance will always be returned when it's resolved
113 replies