Need to register service in app.

builder.Services.AddScoped<IProductService, ProductService>();

Program.cs file of Blazor Client app

    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) });

            // Fetch Data Using Service Layer
            builder.Services.AddScoped<IProductService, ProductService>();

            await builder.Build().RunAsync();
        }
    }
Last modified: November 27, 2020

Author

Comments

Write a Reply or Comment