1
votes

i wan to use Dependency Injection in blazor i am using visual studio preview the latest version i want to add this code in startup.cs

services.AddSingleton<SengaltonServices>();

but i can not find startup.cs in client to inject in Razor component

1

1 Answers

6
votes

For Blazor WASM you setup the DI in Program using WebAssemblyHostBuilder.Services:

public class Program
{
    public static async Task Main(string[] args)
    {
       var builder = WebAssemblyHostBuilder.CreateDefault(args);
       builder.Services.AddSingleton<SengaltonServices>();
       await builder.Build().RunAsync();
    }
}