简体   繁体   中英

How to solve calling Startup.cs from Program.cs?

EDIT

I'm using Blazor WASM project. I'm trying to create an Indexed DB to my project with TG.Blazor.IndexedDB NuGet Package. I create Startup.cs in my project. I have a few error in Program.cs & Startup.cs.

Error CS0246 The type or namespace name 'IComponentsApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)

Starup.cs

using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using TG.Blazor.IndexedDB;


 namespace WebApplication
{
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddIndexedDB(dbStore =>
        {
            dbStore.DbName = "TheFactory";
            dbStore.Version = 1;

            dbStore.Stores.Add(new StoreSchema
            {
                Name = "Employees",
                PrimaryKey = new IndexSpec { Name = "id", KeyPath = "id", Auto = true },
                Indexes = new List<IndexSpec>
                {
                    new IndexSpec{Name="firstName", KeyPath = "firstName", Auto=false},
                    new IndexSpec{Name="lastName", KeyPath = "lastName", Auto=false}

                }
            });
            dbStore.Stores.Add(new StoreSchema
            {
                Name = "Outbox",
                PrimaryKey = new IndexSpec { Auto = true }
            });
        });
    }
//error here 
    public void Configure(IComponentsApplicationBuilder app)
    {
        app.AddComponent<App>("app");
    }
}
 }

Error CS1061 'WebAssemblyHost' does not contain a definition for 'Run' and no accessible extension method 'Run' accepting a first argument of type 'WebAssemblyHost' could be found (are you missing a using directive or an assembly reference?)

Error CS0103 The name 'BlazorWebAssemblyHost' does not exist in the current context

Program.cs

using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using TG.Blazor.IndexedDB;


 namespace WebApplication
{
public class Program
{
    public static async Task Main(string[] args)
    {
        var builder = WebAssemblyHostBuilder.CreateDefault(args);
        builder.RootComponents.Add<App>("#app");

        builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

        await builder.Build().RunAsync();
       
        // error at Run()
        CreateHostBuilder(args).Build().Run();
    }
    public static WebAssemblyHostBuilder CreateHostBuilder(string[] args) =>
        //error at BlazorWebAssemblyHost
       BlazorWebAssemblyHost.CreateDefaultBuilder()
           .UseBlazorStartup<Startup>();
}
}

What I have tried:

Tg.Blazor.IndexedDB

Missing startup.cs program.cs.Net Core Razor

This is the Splash page for Reshiru.Blazor.IndexDB.

It's DEPRECIATED , out of date, and stale. In my book that means don't go near it.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM