0

I need use dependency injection in Blazor WebAssembly app. But there is a situation, my blazor app in UI layer. I will inject dependency from business layer and I need inject data layer too. But UI layer shouldn't access to data layer. How I can fix this? And another question is, can I adapt Ninject in this Program.cs file?

Program.cs

public class Program
{
    public static async Task Main(string[] args)
    {
        var builder = WebAssemblyHostBuilder.CreateDefault(args);
        builder.Services.AddSingleton<IMyBusiness, MyBusiness>();
        builder.Services.AddSingleton<IMyRepository, MyRepository>();
        builder.RootComponents.Add<App>("app");

        await builder.Build().RunAsync();
    }
}
  • 1
    Is your business layer in the WebAsm app? That would be strange. The DataLayer can't be in WebAsm, so this question shouldn't even come up. What does MyRepository depend on? – Henk Holterman Jun 18 '20 at 11:12
  • No. Repositories in DataLayer. Only business layer referenced to WebAsm app. But if I resolve my business layer object in WebAsm, there is error. Because WebAsm want resolve IRepository too. But WebAsm should NOT access to Data layer. – Hüseyin KARACAOĞLU Jun 18 '20 at 11:29
  • 1
    You need an API. Create a new project from the WebAsm+Hosted template and look at the WeatherForecast. – Henk Holterman Jun 18 '20 at 11:37
  • I guess you are right. This can be fix that issue. – Hüseyin KARACAOĞLU Jun 18 '20 at 11:46

0 Answers0