I use the context service as a singletone in the app. What do you think, is this a good way to initialize and use context the way like this (see below) is it better just to use it as disposable? See examples below and write the comments
1. Check if the context doesn't exist and to create it
public ClientContext GetContext(string url)
{
if (_clientContext == null) {
AuthenticationManager authManager = new AuthenticationManager(
_tenantConfig.ClientId,
_tenantConfig.Certificate,
_tenantConfig.TenantId);
_clientContext = authManager.GetContext(url);
}
return _clientContext;
}
2. Make it disposable
public async Task<ClientContext> CreateContextAsync(string url)
{
var authManager = new AuthenticationManager(
_tenantConfig.ClientId,
_tenantConfig.Certificate,
_tenantConfig.TenantId);
return await authManager.GetContextAsync(url);
}

What do to with Zone.Identifier files after importing a WSL machine and copying data
Support for SharePoint Server 2019 ends on Tuesday, July 14, 2026
How to Never Forget Temporary Test Code: Using #if RELEASE + #error in Visual Studio