无法创建接口FirebaseAuthProvider的即时

jbose2ul  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(101)

我正试图为一个学校项目创建一个WPF应用程序我觉得对我的应用程序实现Firebase身份验证是个好主意,我发现了一个视频参考URL:https://www.youtube.com/watch?v=aCEOdnd0-so&list=PLA8ZIAm2I03jn4cDxYTqi40DOHjoOYZCz&index=1
即使我得到了我的窗口打开时,我试图创建一个虚拟用户,我得到一个错误(无法创建一个即时的接口firebaseauthprovider)。我将把代码放在下面的app.xaml.cs文件中。如果有人能为我的问题找到解决方案,那将是一个很大的帮助。谢谢。

using Firebase.Auth;
using Firebase.Auth.Providers;
using Firebase.Auth.Repository;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Threading.Tasks;
using System.Windows;


namespace Key_Auth.wpf
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {

        private readonly IHost host;

        public App()
        {
            // Build the host
            host = Host.CreateDefaultBuilder()
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    // Load configuration from appsettings.json
                    config.SetBasePath(Directory.GetCurrentDirectory());
                    config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

                })
                .ConfigureServices((context, services) =>
                {
                    //get firebase api from configuration
                    string firebaseApiKey = context.Configuration["FIREBASE_API_KEY"];

                    services.AddSingleton<FirebaseAuthProvider>((serviceProvider) =>
                    {
                        // Create a new FirebaseAuthProvider instance with the API key

//here throws me an error
                        var authProvider = new FirebaseAuthProvider(new FirebaseConfig(firebaseApiKey));

                        // Do any additional configuration here, such as setting up a user change event handler

                        return authProvider;
                    });

                    // Register FirebaseAuthProvider as a singleton with a callback

                    // Register services here
                    // For example:
                    // services.AddSingleton<MyService>();
                    // services.AddTransient<MyOtherService>();
                    services.AddSingleton<MainWindow>();

                    // Register MainWindow as a singleton with a callback
                    services.AddSingleton<MainWindow>((serviceProvider) =>
                    {
                        // Get any required dependencies and create the MainWindow instance
                        var mainWindow = new MainWindow();

                        // Do any additional configuration here

                        return mainWindow;
                    });

                })
                .Build();
        }

        protected override async void OnStartup(StartupEventArgs e)
        {
            /*
            base.OnStartup(e);

            // Start the host
            await host.StartAsync();

            // Resolve the main window from the service provider
            var mainWindow = host.Services.GetRequiredService<MainWindow>();

            // Show the main window
            mainWindow.Show();
            */

            base.OnStartup(e);

            // Start the host
            await host.StartAsync();

            // Resolve the main window from the service provider
            var mainWindow = host.Services.GetRequiredService<MainWindow>();

            // Set the main window of the application
            MainWindow = mainWindow;

            // Show the main window
            mainWindow.Show();

            //provider.GetService<FirebaseAuthProvider>();
            //GetRequiredService<FirebaseAuthProvider>();
     
        }

        protected override async void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);

            // Shutdown the host
            await host.StopAsync();
            host.Dispose();
        }
    }
}

字符串
我想创建一个从firebase.auth导入的FirebaseAuthProvider

dgtucam1

dgtucam11#

转到您的项目nuget包管理器,将您安装的FirebaseAuthentication.net包降级到视频教程中使用的确切版本(即版本3.7.2)。只有这样,你才能创建一个FirebaseAuthProvider的瞬间,你才能按照教程学习。此外,请注意,教程的项目是WPF.Net项目,而不是.Net Framework
更新:
但是,如果您希望继续使用最新版本,可以查看package's nuget webpage上的用法示例

相关问题