Skip to content

Some example is needed for using the new version with dependency injection #43

Answered by acupofjose
RedChops asked this question in Q&A
Discussion options

You must be logged in to vote

@RedChops I have been using the Dependency injection model with Maui by specifying Supabase.Client as a Singleton within the builder, and leverage it using an AppStateService class like so:

MauiProgram.cs

static IServiceProvider? serviceProvider;
public static TService? GetService<TService>() => serviceProvider!.GetService<TService>();

public static MauiApp CreateMauiApp() {
// ...
builder.Services.AddSingleton(provider =>
    new Supabase.Client(
	 supabaseUrl,
	 supabaseKey,
	new SupabaseOptions
	{
	    AutoRefreshToken = true,
	    AutoConnectRealtime = true,
	    SessionHandler = new SupabaseSessionHandler()
	}
));

builder.Services.AddSingleton(provider => new AppStateService(provider.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@RedChops
Comment options

@acupofjose
Comment options

Answer selected by RedChops
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants