https://pulumi.com logo
#dotnet
Title
# dotnet
b

bumpy-grass-54508

02/17/2023, 12:07 AM
👋 @echoing-dinner-19531 question about the new .NET resource providers - what is best way to keep track of things like http clients that i create during
Configure
? in
Configure
i read in the provider inputs, build up my implementation-specific http client pointed at my custom API, and store that to a private instance field. then later in
Create
and
Delete
i attempt to use the http client to actually perform the actions i need to. however, i am seeing the client is null during Create, and after some logging i see that my Provider class is being instantiated several times but only once Configured
actually, i may have answered my own question, but leads me to another question - does the pulumi engine execute the resource plugin binary once for each time a provider from that plugin is created? i added some more logging and debugging, and it looks like if i create 2 provider instances inside my pulumi stack, the plugin binary was being ran at least twice. if that is the case, is it safe to just store my provider-specific http client inside a private static field? seems like each provider instance may be isolated in different .net processes
e

echoing-dinner-19531

02/17/2023, 9:17 AM
if that is the case, is it safe to just store my provider-specific http client inside a private static field? seems like each provider instance may be isolated in different .net processes
private instance fields should work. I'll look into this for you! The intention is supposed to be your "Provider" object gets created once when the engine attaches, then the engine call configure allowing you to set up any instance state, and then everything else gets called. I have probably just screwed something up in the AspNet DI layer and not told it that providers should be singletons. For the time being static state will probably be a good workaround, the engine will start a whole new process for each provider instance it sees so you should be safe using static state.
b

bumpy-grass-54508

02/17/2023, 12:17 PM
awesome thank you so much!
e

echoing-dinner-19531

02/18/2023, 12:19 PM
https://github.com/pulumi/pulumi-dotnet/pull/105 Might be a bit before it gets released, company is on a holiday week this week so the next dotnet release will probably be the 1st March.
b

bumpy-grass-54508

02/20/2023, 3:22 PM
ah great thanks for the speedy resolution 🎊
5 Views