Reputation: 21
I have a shared .net 6 project for just controls. I wanted to use the same controls in .Net Blazor Web as with .Net Maui Blazor. I was trying to do this but it doesn't work. Any idea how I can switch what data service is called based on what's calling it?
@*@if(AppDomain.CurrentDomain.FriendlyName == "nu.web")
{
@inject IDataService _db
}
else
{
@inject IHttpService _db
}*@
Thanks for any help...
Upvotes: 0
Views: 852
Reputation: 21
From Bennyboy1973’s hint… I removed the extra interface IHttpService and used IDataService on both HttpService and DataService.
Then on the .Net Blazor web app startup.cs file: builder.Services.AddSingleton<IDataService, DataService>();
Then on the .Net Maui Blazor app MauiProgram.cs file: builder.Services.AddSingleton<IDataService, HttpService>();
If anyone cares about why I wanted it this way… I get a slight performance improvement from calling SQL via Dapper on web and .Net Maui doesn’t allow it… So I’m calling the same Dapper SQL via Minimal API.
Thanks again for all the answers
Upvotes: 1