You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For this reason, you should create your Chroma instance once at application startup and then use this instance for the remainder of your application's lifetime.
I don't see a way to just create the instance once and use it for the whole lifetime.
It could be that I'm skipping something really obvious. Hope you can help
Regards, Michael
The text was updated successfully, but these errors were encountered:
This will depend on how your application is designed. Assuming version 6.0 of Colore (v5.2 has built-in singleton behaviour), you could have something like this:
internalstaticclassMyColore{privatestaticIChroma_chroma;publicstaticasyncTask<IChroma>GetInstanceAsync(){if(_chroma!=null){return_chroma;}// Or use CreateRestAsync() if you need/want the Chroma REST API._chroma=await ColoreProvider.CreateNativeAsync();return_chroma;}}
And then whenever you need the instance, you can retrieve it like this:
publicstaticclassProgram{publicstaticasync Task Main(){varchroma=await MyColore.GetInstanceAsync();// Do stuff with the IChroma instance in `chroma`}}
This is known as the "singleton pattern". There's an article on C# in Depth that explains it in more detail.
Hopefully that points you in the right direction :)
Oh, thank you.
I actually never worked with a Singleton Pattern got me really confused.
Maybe it would be nice if this could even be put into the Getting Started Wiki page?
For other People that maybe didn't understand it or never worked with it.
Hey, in Getting Started there is the sentence
I don't see a way to just create the instance once and use it for the whole lifetime.
It could be that I'm skipping something really obvious. Hope you can help
Regards, Michael
The text was updated successfully, but these errors were encountered: